protected static WindsorContainer CreateContainerForEventStoreType(Func<IReadOnlyList<IEventMigration>> migrationsfactory, Type eventStoreType, string eventStoreConnectionString = null)
{
var container = new WindsorContainer();
container.ConfigureWiringForTestsCallBeforeAllOtherWiring();
container.Register(
Component.For<IUtcTimeTimeSource, DummyTimeSource>()
.Instance(DummyTimeSource.Now)
.LifestyleSingleton(),
Component.For<IServiceBus>()
.ImplementedBy<SynchronousBus>()
.LifestylePerWebRequest(),
Component.For<IEnumerable<IEventMigration>>()
.UsingFactoryMethod(migrationsfactory)
.LifestylePerWebRequest(),
Component.For<IEventStoreSession, IUnitOfWorkParticipant>()
.ImplementedBy<EventStoreSession>()
.LifestylePerWebRequest(),
Component.For<IWindsorContainer>().Instance(container)
);
if (eventStoreType == typeof(SqlServerEventStore))
{
if(eventStoreConnectionString == null)
{
var masterConnectionSTring = new ConnectionStringConfigurationParameterProvider().GetConnectionString("MasterDB");
var dbManager = new TemporaryLocalDbManager(masterConnectionSTring.ConnectionString, container);
eventStoreConnectionString = dbManager.CreateOrGetLocalDb($"{nameof(EventStreamMutatorTestsBase)}_EventStore");
}
container.Register(
Component.For<IEventStore>()
.ImplementedBy<SqlServerEventStore>()
.DependsOn(Dependency.OnValue<string>(eventStoreConnectionString))
.LifestyleScoped());
}
else if(eventStoreType == typeof(InMemoryEventStore))
{
container.Register(
Component.For<IEventStore>()
.UsingFactoryMethod(
kernel =>
{
var store = kernel.Resolve<InMemoryEventStore>();
store.TestingOnlyReplaceMigrations(migrationsfactory());
return store;
})
.LifestyleScoped(),
Component.For<InMemoryEventStore>()
.ImplementedBy<InMemoryEventStore>()
.LifestyleSingleton());
}
else
{
throw new Exception($"Unsupported type of event store {eventStoreType}");
}
container.ConfigureWiringForTestsCallAfterAllOtherWiring();
return container;
}