/// <summary> /// Initialises a new instance of the <see cref="Kernel"/> class. /// </summary> /// <param name="deviceSettings">Platform-specific device settings</param> /// <param name="persistedApplicationStateRepository">Platform-specific repository for the application state</param> public Kernel( IDeviceSettings deviceSettings, IPersistedApplicationStateRepository persistedApplicationStateRepository) { this.deviceSettings = deviceSettings; this.persistedApplicationStateRepository = persistedApplicationStateRepository; var applicationStateFactory = new CurrentApplicationStateFactory(this.GetCurrentApplicationState); this.bootstrap = new Bootstrap(persistedApplicationStateRepository, applicationStateFactory); var vectorClock = new VectorClock(); var eventStoreState = new EventStoreState(); this.bootstrap.EventStore.State = eventStoreState; this.bootstrap.VectorClock.SetState(vectorClock); this.bootstrap.DeviceId.SetDeviceId(deviceSettings.GetDeviceId()); this.Repositories = new ReadRepositories(this.bootstrap); this.CommandBus = this.bootstrap.CommandBus; Messenger.Default.Register <LoadApplicationStateRequested>(this, x => this.LoadApplicationState(x.Location)); this.ResetReadModelState(); }
/// <summary> /// Initialises a new instance of the <see cref="Bootstrap"/> class. /// </summary> /// <param name="persistedApplicationStateRepository">Application state repository for access to the persisted application state</param> /// <param name="applicationStateFactory">Factory for the current application state</param> public Bootstrap( IPersistedApplicationStateRepository persistedApplicationStateRepository, ICurrentApplicationStateFactory applicationStateFactory) { this.Container = this.CreateContainer(persistedApplicationStateRepository, applicationStateFactory); RegisterKnownTypesForSerialisation(); }
/// <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); }
/// <summary> /// Initialises a new instance of the <see cref="ApplicationStateService"/> class. /// </summary> /// <param name="repository">Persisted application state repository</param> /// <param name="factory">Current application state factory</param> public ApplicationStateService(IPersistedApplicationStateRepository repository, ICurrentApplicationStateFactory factory) { this.repository = repository; this.factory = factory; }