/// <summary> /// Setup the dependency injection /// </summary> /// <returns>Initialised dependency injection container</returns> /// <param name="persistedApplicationStateRepository">Application state repository for access to the persisted application state</param> /// <param name="applicationStateFactory">Factory for the current application state</param> private IContainer CreateContainer( IPersistedApplicationStateRepository persistedApplicationStateRepository, ICurrentApplicationStateFactory applicationStateFactory) { var simpleInjector = new Container(); // Application state repository is required when we want to save current the application state simpleInjector.RegisterSingleton <IPersistedApplicationStateRepository>(persistedApplicationStateRepository); simpleInjector.RegisterSingleton <ICurrentApplicationStateFactory>(applicationStateFactory); // Event store only exists once (the state can be exchanged at runtime though) this.EventStore = new EventStore(); simpleInjector.RegisterSingleton <IEventStore>(this.EventStore); simpleInjector.RegisterSingleton <IReadOnlyEventStore>(this.EventStore); // Device Id var deviceId = new DeviceId(); this.DeviceId = deviceId; simpleInjector.RegisterSingleton <IDeviceId>(this.DeviceId); simpleInjector.RegisterSingleton <IReadOnlyDeviceId>(this.DeviceId); // Vector clock this.VectorClock = new MasterVectorClock(deviceId); simpleInjector.RegisterSingleton <IVectorClock>(this.VectorClock); // Core messaging infrastructure this.EventBus = new EventBus(); simpleInjector.RegisterSingleton <IEventBus>(this.EventBus); // Initialise the command bus last because it depends on many other objects this.CommandBus = new CommandBus( simpleInjector, this.EventBus, this.DeviceId, this.VectorClock, this.EventStore); simpleInjector.RegisterSingleton <ICommandBus>(this.CommandBus); // Read store (for read side repositories) // same singleton for read and reset var readStore = new ReadStore(); simpleInjector.RegisterSingleton <IReadStore>(readStore); simpleInjector.RegisterSingleton <IResetableReadStore>(readStore); simpleInjector.RegisterSingleton <IReadStoreResetBroadcast>(readStore); // Must also register container itself because infrastructure needs it simpleInjector.RegisterSingleton <IContainer>(simpleInjector); // Sub-registrations (must not depend on each other) this.RegisterCommandHandlers(simpleInjector); this.RegisterProjectionRepositories(simpleInjector); this.RegisterProjections(simpleInjector, this.EventBus); simpleInjector.Verify(); return(simpleInjector); }
public void SetUp() { var deviceId = new DeviceId(); deviceId.SetDeviceId(new Guid("D7BD15B7-AB64-41FE-994D-5DC8E2E8C9D8")); var vectorClock = new MasterVectorClock(deviceId); var eventStore = new EventStore(); var messageBus = new EventBus(); this.unitOfWork = new UnitOfWork(deviceId, vectorClock, eventStore, messageBus); }