public static IDomainContext GetDomainContext() { var eventSerializer = new DataContractSerializer <EventBase>(TypeHelpers.FindSerializableTypes(typeof(EventBase), Assembly.GetCallingAssembly())); var context = new EventSourcedDomainContext(EventSourcedDB.SampleDatabasePath(), ReadModelDB1.SampleDatabasePath(), eventSerializer); context.EventBus.Subscribe((x) => Console.WriteLine("domain bus event {0}", x)); var registration = AggregateRegistration.ForType <EventSourcedRoot>() .WithImmediateReadModel(c => new TransactionReadModelBuilder(new SqlRepository <TransactionDataContract>(EventSourcedDB.Main, "TestId"))); context.Register(registration); return(context); }
public static void InitSample() { if (Remote == null) { TestId = Guid.NewGuid(); var eventSerializer = new DataContractSerializer <EventBase>(TypeHelpers.FindSerializableTypes(typeof(EventBase), Assembly.GetCallingAssembly())); var commandSerializer = new DataContractSerializer <CommandBase>(TypeHelpers.FindSerializableTypes(typeof(CommandBase), Assembly.GetCallingAssembly())); Remote = new EventSourcedDomainContext(RemoteDB.SampleDatabasePath(), eventSerializer); Client1 = new EventSourcedDomainContext(Client1DB.SampleDatabasePath(), ReadModelDB1.SampleDatabasePath(), eventSerializer) { CommandSerializer = commandSerializer }; Client2 = new EventSourcedDomainContext(Client2DB.SampleDatabasePath(), ReadModelDB2.SampleDatabasePath(), eventSerializer) { CommandSerializer = commandSerializer }; var registration = AggregateRegistration.ForType <EventSourcedRoot>(); // .WithImmediateReadModel(c => new TransactionReadModelBuilder(new SqlRepository<TransactionDataContract>(EventSourcedDB.Main, "TestId"))); Client1.Register(registration.WithDelayedReadModel( // TODO: pass in read model db as a scope scope => new TransactionReadModelBuilder(new SqlRepository <TransactionDataContract>(scope, "TestId")))); Client1.StartDelayedReadModels(); Client2.Register(registration); } }