Ws.Maui.LocalDB.Sync is a lightweight, modular sync library for .NET MAUI apps that need offline-first functionality. It provides an extensible and testable mechanism to sync remote data with a local SQLite database using a clean and pluggable architecture.
- ✅ Sync remote data into a local SQLite database
- 🔄 Conflict resolution strategies (Prefer Local, Prefer Remote, Custom Merge)
- 🧹 Optional TTL (time-to-live) data pruning support
- 📡 Incremental sync support (Last-Modified or ETag ready)
- 🔁 Retry logic for remote fetch/save operations
- ⚙️ Works great with .NET MAUI and SQLite-net-pcl
dotnet add package Ws.Maui.LocalDB.Syncpublic class Article : ISyncableEntity<Guid>
{
public Guid Id { get; set; }
public DateTime LastModified { get; set; }
public string Title { get; set; }
public string Content { get; set; }
}var store = new SQLiteStore<Article, Guid>("path/to/your.db");var manager = new SyncManager<Article, Guid>(
fetchRemote: async () => await remoteService.GetArticlesAsync(),
fetchLocal: store.GetAllAsync,
saveLocal: store.SaveAsync,
resolveConflict: new PreferRemoteStrategy<Article>().Resolve
);
var results = await manager.SyncAsync();Supports tracking the last sync timestamp using ISyncMetadataProvider:
public interface ISyncMetadataProvider<TKey>
{
Task<DateTime?> GetLastSyncedUtcAsync(TKey scope);
Task SetLastSyncedUtcAsync(TKey scope, DateTime timestamp);
}Pass it into the SyncManager constructor to enable automatic timestamp tracking.
Use ITtlPolicy<T> to delete expired records automatically:
public class ArticleTtlPolicy : ITtlPolicy<Article>
{
public bool ShouldDelete(Article article) =>
article.LastModified < DateTime.UtcNow.AddDays(-30);
}All fetch/save operations can be wrapped with retry logic to improve resilience:
await RetryHelper.ExecuteWithRetry(() => store.SaveAsync(items));Each SyncResult<T> contains an Exception? Error field to track failed operations.
- TTL Pruning Support
- Retry + Error Tracking
- Incremental Sync via Metadata
- NuGet Packaging & Versioning
- Platform-specific samples (Android, Windows, etc)
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions and suggestions are welcome! Please open an issue or submit a pull request.
Built with ❤️ for developers who need reliable offline sync in cross-platform apps.