{"id":22660606,"url":"https://github.com/sebcam/CrossSync","last_synced_at":"2025-08-06T09:32:43.017Z","repository":{"id":34921316,"uuid":"144736231","full_name":"sebcam/CrossSync","owner":"sebcam","description":"Provides Mobile / Server synchronization with offline support using .NetCore and EntityFramework.Core","archived":false,"fork":false,"pushed_at":"2023-01-06T20:20:13.000Z","size":298,"stargazers_count":17,"open_issues_count":3,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-01T10:27:51.201Z","etag":null,"topics":["entity-framework-core","mvvm","netcore","netcore-webapi","offline-sync","sqlite","sqlserver","synchronization","xamarin","xamarin-forms"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebcam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-14T15:06:44.000Z","updated_at":"2023-02-14T21:50:18.000Z","dependencies_parsed_at":"2023-01-15T10:25:50.427Z","dependency_job_id":null,"html_url":"https://github.com/sebcam/CrossSync","commit_stats":null,"previous_names":["sebastiencambon/coresync"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebcam%2FCrossSync","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebcam%2FCrossSync/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebcam%2FCrossSync/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebcam%2FCrossSync/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebcam","download_url":"https://codeload.github.com/sebcam/CrossSync/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228657293,"owners_count":17952700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["entity-framework-core","mvvm","netcore","netcore-webapi","offline-sync","sqlite","sqlserver","synchronization","xamarin","xamarin-forms"],"created_at":"2024-12-09T11:10:51.038Z","updated_at":"2024-12-09T11:10:53.380Z","avatar_url":"https://github.com/sebcam.png","language":"C#","readme":"# CrossSync\n![.NetCore](https://img.shields.io/badge/.NetCore-2.1-blue.svg) ![.NetStandard](https://img.shields.io/badge/.NetStandard-2.0-blue.svg)\n\nCrossSync provides cross-plaform librairies for Xamarin and AspNetCore for easy data synchronization with offline data support based on Entity Framework Core.\n\n### Why ?\n\nEntity Framework Core now offers a way to share the business data code between the mobile and server applications.\n\nFor now, Azure Mobile App is the most popular framework to do this. But it's working with .NetFramework and bring it to .NetCore seems to be not announced yet.\nSo to work with Azure Mobile App, your data layer cannot be shared across these different platforms.\n\nThis libs can be usefull for developpers which are looking for a way to synchronize offline datas on your mobile application using Entity Framework Core.\n\nHigh level features are :\n\n - EntityFramework use for both mobile (SQLite) and API (SQL Server)\n - Offline data support\n - Repository \u0026 Unit of work patterns\n - ...\n\n## Top level Packages\n| Name | Description | Nuget |\n| ---- | ----------- | ----- |\n| `CrossSync.AspNetCore` | Provides aspnet core sync tools | ![Version](https://img.shields.io/badge/-0.1.0-blue.svg) |\n| `CrossSync.Xamarin`| Provides all implementations for mobile data offline and sync | ![Version](https://img.shields.io/badge/-0.1.0-blue.svg) |\n\n## Get Started\n\n### Server side\n\nOn your AspNetCore API Project :\n\n    nuget install CrossSync.AspNetCore\n\n##### Entity framework configuration\nIf you are not aware with EF, see [EF Core docs](https://docs.microsoft.com/en-us/ef/core/)\n\nYour **DbContext** have to inherit from **ServerContext** class. \n\nAll of your entities which need to be synchronized with mobile have to extend **VersionableEntity** class.\n\n 1. Your entities have to inherit from **VersionableEntity** class or implement **IVersionableEntity**.\n 2. Your EF Context have to inherit from **ServerContext** class.\n\n##### Controllers configuration\n\nControllers have to inherit from **SyncController** which is a crud controller.\n\nWhen you are done, juste add sync registration into your startup.cs :\n\n    public void ConfigureServices(IServiceCollection services)\n    {\n\t  /* ... */\n\t  \n\t  // Sync services registration\n\t  services.AddSync();\n    }\n    \n\n### Client Side using Xamarin.Forms\n\n#### Installation\nOn your Core assembly : \n\n    nuget install CrossSync.Xamarin\n\n#### Configuration\n\nThis library needs to know about the connectivity status.\n\nCreate a class which implements IConnectivityService.\nFor example, the following uses the [Plugin Connectivity](https://github.com/jamesmontemagno/ConnectivityPlugin) from James Montemagno.\n\n    public class ConnectivityService : IConnectivityService\n    {\n        private readonly IConnectivity connectivity;\n\n        public ConnectivityService(IConnectivity connectivity)\n        {\n            this.connectivity = connectivity;\n        }\n\n        public bool IsConnected =\u003e connectivity.IsConnected;\n\n        public Task\u003cbool\u003e IsRemoteReachable(string url)\n        {\n            return connectivity.IsRemoteReachable(url);\n        }\n    }\n\nIt also need a service to show errors during synchornization by implementing IErrorService.\nFor example, the following uses [Acr UserDialogs](https://github.com/aritchie/userdialogs) :\n\n\n    public class ErrorService : IErrorService\n    {\n        private readonly IUserDialogs dialogs;\n\n        public ErrorService(IUserDialogs dialogs)\n        {\n            this.dialogs = dialogs;\n        }\n        public void ShowError(string error)\n        {\n            using (dialogs.Toast(new ToastConfig(error) { Duration = new TimeSpan(0, 0, 2), Position = ToastPosition.Top })) { }\n        }\n    }\n\nThe last step is to register services to the IoC container :\n\n    // using autofac\n    builder.RegisterType\u003cErrorService\u003e().AsImplementedInterfaces().SingleInstance();\n    builder.RegisterType\u003cConnectivityService\u003e().AsImplementedInterfaces().SingleInstance();\n    builder.RegisterType\u003cSynchronizationService\u003e().AsSelf().InstancePerLifetimeScope();\n\n\n#### How to use\n\n##### Business Data Services implementation \n\n    public class TodoListService : SyncService\u003cEntities.Shared.TodoList\u003e\n    {\n        private readonly IUnitOfWork\u003cTodoListContext\u003e unitOfWork;\n\n        public TodoListService(IUnitOfWork\u003cTodoListContext\u003e unitOfWork, IConnectivityService connectivityService, Lazy\u003cIErrorService\u003e errorService, SyncConfiguration config) : base(unitOfWork, connectivityService, errorService, config)\n        {\n            this.unitOfWork = unitOfWork;\n        }\n\n        public override string ApiUri =\u003e \"api/todolist\";\n\n        // Order in which sync is done between services depending on data relations\n        public override int Order =\u003e 100;\n    }\n\n##### Start a synchronization\n\nSynchronization, for now, have to be manually launched like this :   \n\n    // Resolve the registrated sync service\n    var synchronizationService = IoC.Resolve\u003cSynchronizationService\u003e();\n    // Starts the synchronization\n    await synchronizationService.SyncAsync();\n\nSoon, the synchronization will be done within an async background task.\n\n##### Handle conflicts\n\nIn order to handler version conflicts between offline and server datas, you need to implement IConflictHandler\u003c\u003e on your data service\n\n    public class TodoListService : SyncService\u003cEntities.TodoList\u003e, IConflictHandler\u003cEntities.Shared.TodoList\u003e\n    {\n        /* ... */\n\n        public async Task\u003cEntities.Shared.TodoList\u003e HandleConflict(Entities.Shared.TodoList clientValue, Entities.Shared.TodoList serverValue)\n        {\n            // Ask for user to choose between client and server version\n            var selectedResult = await IoC.Resolve\u003cIUserDialogs\u003e().ActionSheetAsync(\"Conflict resolution\", \"Keep local version\", null, buttons: new[] { \"Take Server version\" });\n            return selectedResult == \"Keep local version\" ? clientValue : serverValue;\n        }\n    }\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebcam%2FCrossSync","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebcam%2FCrossSync","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebcam%2FCrossSync/lists"}