Open Closed

Disconnected Tiered App #10223


User avatar
0
Fabio.Zinesi created

Hi,

we have a tiered application with blazor and SQL Server.

I need to make the app working also with no connection.

It's possible to create a local middleware with the same API and a local database?


3 Answer(s)
  • User Avatar
    0
    AI-Bot created
    Support Team ABP Agent
    1. Solution Short answer: Yes, but you must design it explicitly. ABP doesn’t provide an “offline mode” out of the box. For a tiered Blazor + SQL Server solution, you can support “no-connection” operation by running a local “edge host” that exposes the same HTTP API contracts and uses a local database (e.g., SQLite). When connectivity returns, you sync data with the central server.

    Key steps:

    • Keep API contracts identical

      • Put your application service interfaces in the HttpApi.Client project and make sure all endpoints are defined by Application Services that implement IApplicationService and are exposed by your HttpApi.Host.
      • Your Blazor front end should only call those interfaces via ABP’s dynamic C# API clients. That way, when you switch between remote and local hosts, the client stays the same.
    • Provide two hosts with the same API surface

      • Central host (already exists): HttpApi.Host + SQL Server.
      • Local host (new): a lightweight ASP.NET Core host that depends on the same Application layer but configured with a local DB provider (e.g., EF Core + SQLite) and runs alongside the Blazor app on the client machine (or inside the same machine/VM). Example module dependency:
    [DependsOn(
            typeof(MyProjectApplicationModule),
            typeof(MyProjectHttpApiModule),
            typeof(AbpAspNetCoreMvcModule)
        )]
        public class MyProjectLocalHostModule : AbpModule
        {
            public override void ConfigureServices(ServiceConfigurationContext context)
            {
                // Configure EF Core to SQLite for local store
                Configure<AbpDbConnectionOptions>(options =>
                {
                    options.ConnectionStrings.Default = "Data Source=local.db";
                });
            }
        }
    
    • Switch endpoints based on connectivity
      • Configure the Blazor app’s RemoteServiceOptions to point to the “remote” host normally, and to the “local” host when offline.
      • You can detect connectivity and toggle BaseUrls at startup or on-the-fly:
    public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            PreConfigure<AbpRemoteServiceOptions>(options =>
            {
                var isOffline = /* your connectivity check */;
                options.RemoteServices.Default = new RemoteServiceConfiguration(
                    baseUrl: isOffline ? "https://localhost:5005" : "https://central-host.example.com"
                );
            });
        }
    
    • Optionally, add Polly retry logic to smooth transitions.

    • Use a local EF Core provider

      • For the local host, configure DbContext to SQLite, file-based, to avoid SQL Server dependency offline.
      • Keep the same DbContext and entities so the API behaves identically.
    • Authentication considerations

      • If you use OpenIddict/Identity on the central host, offline login won’t work by default. For offline, consider:
        • Caching auth tokens for a grace period, or
        • Running a minimal local auth with the same users/permissions synced periodically.
      • This is a product decision: offline mode typically implies limited or cached authorization.
    • Data synchronization (when back online)

      • Implement a sync process between local and central databases:
        • Track changes locally (Created/Updated/Deleted timestamps or change tracking tables).
        • On reconnection, push local changes via the same application services, then pull server changes.
        • Handle conflict resolution (server-wins, client-wins, or merge).
      • You can use background workers (IHostedService) on the local host to attempt sync periodically when connectivity is restored.
    • Caching and queues

      • Prefer local implementations when offline:
        • IDistributedCache → use a local provider (e.g., Memory) for the local host.
        • Distributed event bus → use local event bus (no broker) on the local host, and publish to the server only during sync phases.
    • Blazor hosting choice

      • Blazor Server requires a live SignalR connection to a server. For true offline usage, consider:
        • Running the local host on the same machine and connecting Blazor Server to it when offline, or
        • Moving to Blazor WebAssembly (PWA) for the UI so the UI itself loads offline and calls the local host API.
      • If you stay with Blazor Server, the “server” must be reachable locally during offline; that means your local host must be running and the client connects to it.
    • Minimal local host example

    public class Program
      {
          public static async Task Main(string[] args)
          {
              var builder = WebApplication.CreateBuilder(args);
    
              // SQLite connection for local mode
              builder.Services.Configure<AbpDbConnectionOptions>(options =>
              {
                  options.ConnectionStrings.Default = builder.Configuration.GetConnectionString("Default");
              });
    
              await builder.AddApplicationAsync<MyProjectLocalHostModule>();
              var app = builder.Build();
    
              await app.InitializeApplicationAsync();
              app.MapControllers();
              await app.RunAsync();
          }
      }
    

    appsettings.json (local): { "ConnectionStrings": { "Default": "Data Source=local.db" }, "App": { "SelfUrl": "https://localhost:5005" } }

    What ABP gives you vs what you must implement

    • ABP provides: modular layers, dynamic C# API clients, EF Core integration, background workers, caching abstraction.
    • You must implement: the local host, endpoint switching, offline auth strategy, and data synchronization logic and conflict handling.

    This approach aligns with common ABP conventions, but specific official documentation for an “offline local middleware with identical API + sync back to central SQL Server” is not available.

    1. Sources
    • ABP Framework GitHub (architecture, dynamic proxies, modules are visible in repo):
      • https://github.com/abpframework/abp

    This response was generated by AI. If it didn’t solve your problem, feel free to post a new answer — our support team will jump in to help you soon.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Do you mean no internet or offline?

    Apps need to be able to communicate with each other(http).

    Thanks.

  • User Avatar
    0
    Fabio.Zinesi created

    Hi Mailming,

    i mean no internet or offline.

    The answer generated by AI could work?

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.1.0-preview. Updated on December 16, 2025, 09:09
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.