How can I run offline database usage in Blazor WebAssembly-PWA?

Viewed 8621

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.

4 Answers

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.

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.

Related