Ws.Maui.LocalDB.Sync 1.0.0

dotnet add package Ws.Maui.LocalDB.Sync --version 1.0.0
                    
NuGet\Install-Package Ws.Maui.LocalDB.Sync -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Ws.Maui.LocalDB.Sync" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Ws.Maui.LocalDB.Sync" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Ws.Maui.LocalDB.Sync" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Ws.Maui.LocalDB.Sync --version 1.0.0
                    
#r "nuget: Ws.Maui.LocalDB.Sync, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Ws.Maui.LocalDB.Sync@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Ws.Maui.LocalDB.Sync&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Ws.Maui.LocalDB.Sync&version=1.0.0
                    
Install as a Cake Tool

Ws.Maui.LocalDB.Sync

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.

NuGet License: MIT


๐ŸŒŸ Features

  • โœ… 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

๐Ÿ“ฆ Installation

NuGet

dotnet add package Ws.Maui.LocalDB.Sync

๐Ÿงฉ Basic Usage

1. Implement Your Entity

public class Article : ISyncableEntity<Guid>
{
    public Guid Id { get; set; }
    public DateTime LastModified { get; set; }
    public string Title { get; set; }
    public string Content { get; set; }
}

2. Initialize a SQLiteStore

var store = new SQLiteStore<Article, Guid>("path/to/your.db");

3. Create Your SyncManager

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();

๐Ÿ”„ Incremental Sync Support (Advanced)

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.


๐Ÿงผ TTL Policies (Optional Pruning)

Use ITtlPolicy<T> to delete expired records automatically:

public class ArticleTtlPolicy : ITtlPolicy<Article>
{
    public bool ShouldDelete(Article article) =>
        article.LastModified < DateTime.UtcNow.AddDays(-30);
}

๐Ÿ” Retry & Error Handling

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.


โœ… To Do

  • TTL Pruning Support
  • Retry + Error Tracking
  • Incremental Sync via Metadata
  • NuGet Packaging & Versioning
  • Platform-specific samples (Android, Windows, etc)

๐Ÿ“„ License

This project is licensed under the MIT License. See the LICENSE file for details.


๐Ÿ’ฌ Contributing

Contributions and suggestions are welcome! Please open an issue or submit a pull request.


๐Ÿ™Œ Credits

Built with โค๏ธ for developers who need reliable offline sync in cross-platform apps.


Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 154 6/19/2025