-
Notifications
You must be signed in to change notification settings - Fork 8
Quick start
In order to use Realmius you need to set up Realm on the client-side and Entity Framework on the server-side.
Install-Package Realmius.Server- Inherit your DbContext from
ChangeTrackingDbContext:
public class MyDbContext : DbContextChangeTrackingDbContext- All your syncable EF-entities should implement
IRealmiusObjectServer:
public class Message : IRealmiusObjectServer //assume Message is a class backing up the Message table
{
public string Id { get; set; }
public string MobilePrimaryKey => Id;
public string Text { get; set; }
}- Initialize the synchronization process from the
Configuremethod of OWINStartupclass of your web application (if there's no Startup class go ahead andAdd New Item->Owin Startupdetails)
RealmiusServer.SetupShareEverythingSignalRServer(
"/Realmius", // URL Realmius server will be started on (also URL the client will connect to)
app, // this is ASP.Net's IAppBuilder
() => new MyDbContext(), // factory-method which will create your DbContext
typeof(Message) // types you want to be synchronized (you can add as many as you wish)
);
Now just create new Message objects and Save them via EntityFramework as you usually do. They will be automatically synced to the clients as they connect.
The example will share all the Messages between all the clients! For setting up advanced authentication and row level security continue to Advanced section.
-
Install-Package Realmius(if it's a PCL, make sure it's Profile 111/76. if it's not Xamarin project make sure it's at least .NET 4.6.1) - All your syncable Realm entities should implement
IRealmiusObjectClientand have a class name exactly matching classname on the server:
public class Message : RealmObject, IRealmiusObjectClient
{
public string Id { get; set; }
public string MobilePrimaryKey => Id;
public string Text { get; set; }
}- Initialize the synchronization process:
SyncServiceFactory.CreateUsingSignalR(
() => Realm.GetInstance(), // factory-method which will create your Realm instance
new Uri("http://localhost/Realmius"), // URL the client will connect to
new[]
{
typeof(Message) // types you want to be synchronized (you can add as many as you wish)
});You are done!
Now you can query objects, that were added from the server, or add objects to your realm and they will be synced to the server automatically!
Note: to remove objects you have to call Realmius method manually (since Realm doesn't provide any meaningfull change-notification for removed objects)
realm.Write(() =>
{
realm.RemoveAndSync(obj); //RemoveAndSync instead of realm.Remove(obj);
});
For syncing references head over to Advanced section