using Microsoft.Extensions.Logging; using ZB.MOM.WW.LocalDb.Internal; namespace ZB.MOM.WW.LocalDb.Replication.Internal; /// /// Shared construction of a and its dependencies (OplogStore + LwwApplier) /// from a and the bound options. Both the service and client adapters use /// this so they build an identical session; snapshot hooks are left null (Task 12 fills them in). /// internal static class SyncSessionFactory { /// /// The engine binds to internals (NodeId, Clock, replicated-table /// digests), so both adapters require the concrete type AddZbLocalDb registers behind ILocalDb. /// public static SqliteLocalDb RequireSqlite(ILocalDb db, string consumer) => db as SqliteLocalDb ?? throw new InvalidOperationException( $"{consumer} requires the ILocalDb registered by AddZbLocalDb (a {nameof(SqliteLocalDb)}); " + $"got {db.GetType().FullName}."); public static SyncSession Create(SqliteLocalDb db, ReplicationOptions options, ILoggerFactory loggerFactory) { var store = new OplogStore(db, options); var applier = new LwwApplier(db); var logger = loggerFactory.CreateLogger(); return new SyncSession(db, store, applier, options, logger); } }