10

I have a Blazor WebAssembly ASP.NET Core hosted - PWA application and want to run it offline. The database is currently built with SQLite and EF-Core. Is it possible to add offline functionality? I have read about IndexedDB but don't actually know how to implement that into the project (client-side). Or is there any NuGet Package for this support?

The functionality I want to bring into the project is - tracking local changes and fetching them to the DB when its online again.

Chris
  • 2,959
  • 1
  • 30
  • 46
brstkr
  • 1,423
  • 3
  • 18
  • 28
  • Ah, hosted is not webassembly, you know. And your database (sqlLite) is not exactly webassembly either. Also sqllite would not really handle syncing- that requires programming.Easy answer thus is NO. Hosted model runs on the server, not using WebAssembly. – TomTom Jul 05 '20 at 19:33
  • 1
    @TomTom It is WebAssembly Client-Side but in addition with the Server-Side. So at runtime the server is building up the client and they can communicate via Http Requests. The "offline" DB should be in a way in the client project and fetch via Http request to the server DB. The only problem is I don't know how to do that ^^.. – brstkr Jul 05 '20 at 20:34

4 Answers4

6

I've created a library that provides bi-directional offline sync for mobile clients that should do the job: https://github.com/stefffdev/NubeSync

Especially handling conflict resolution when multiple clients did change a record can become tricky, so you could use that as a starting point.

I plan to create a blazor wasm offline sample and blog about it soon.

stefffdev
  • 176
  • 1
  • 9
  • Hi, I'm looking at the sample for Blazor WASM and it's confusing me. It seems to call the server via http client directly from your Razor pages. Does this provide a persistent cache for when an app is offline for multiple days (allowing user to continue working) then syncs once online? – Waleed Al Harthi Sep 13 '21 at 11:27
  • Hi, you are right, in the provided sample I'm just calling REST calls without any offline capability. Currently I am not working on a Blazor offline client since we are not developing Blazor apps right now. A few infos on that you can find here https://github.com/stefffdev/NubeSync/issues/22 – stefffdev Sep 15 '21 at 04:41
2

You can try this package. This is a Blazor library to work with IndexedDB DOM API

https://github.com/amuste/DnetIndexedDb

copycat_am
  • 225
  • 1
  • 6
1

I'm using event sourcing to solve this problem. It deals well with syncing occasionally connected clients as described here. It means dropping entity framework and probably rearchitecting your entire persitance tech stack, so it is far from ideal. But if you plan on building a large complicated system, this is the way to go.

DharmaTurtle
  • 6,858
  • 6
  • 38
  • 52