public static Bootstrapper UseMicrosoftDependencyInjection(this Bootstrapper bootstrapper, IServiceCollection services, params string[] excludedDllsForAutoRegistration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var service = new MicrosoftDependencyInjectionService (_ => { AddComponentRegistrationToContainer(services, bootstrapper.IoCRegistrations.ToList()); AddAutoRegisteredTypes(bootstrapper, services, excludedDllsForAutoRegistration); services.AddScoped <IScopeFactory>(s => new MicrosoftScopeFactory(s)); services.AddScoped <IScope>(s => s.GetRequiredService <IScopeFactory>().CreateScope()); DIManager.Init(new MicrosoftScopeFactory(services)); } ); bootstrapper.AddService(service); return(bootstrapper); }
/// <summary> /// Configure the bootstrapper to use InMemory buses for dispatching events. /// </summary> /// <param name="bootstrapper">Instance of boostrapper.</param> /// <param name="configuration">Configuration to use for in memory event bus.</param> /// <param name="excludedEventsDLLs">DLLs name to exclude from auto-configuration into IoC /// (IAutoRegisterType will be ineffective).</param> public static Bootstrapper UseInMemoryEventBus(this Bootstrapper bootstrapper, InMemoryEventBusConfiguration configuration = null, params string[] excludedEventsDLLs) { var service = InMemoryBusesBootstrappService.Instance; service.BootstrappAction += (ctx) => { InMemoryEventBus.InitHandlersCollection(excludedEventsDLLs); if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC)) { bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(InMemoryEventBus), typeof(IDomainEventBus), typeof(InMemoryEventBus))); if (configuration != null) { bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(configuration, typeof(InMemoryEventBusConfiguration))); } } bootstrapper.AddNotifications(PerformEventChecksAccordingToBootstrapperParameters(ctx, configuration)); }; if (!bootstrapper.RegisteredServices.Any(s => s == service)) { bootstrapper.AddService(service); } return(bootstrapper); }
/// <summary> /// Use RabbitMQ Server to listen from events on a specific rabbitMQ instance. /// </summary> /// <param name="bootstrapper">Bootstrapper instance.</param> /// <param name="configuration">Configuration to use RabbitMQ</param> /// <returns>Bootstrapper instance</returns> public static Bootstrapper UseRabbitMQServer(this Bootstrapper bootstrapper, RabbitMQServerConfiguration configuration = null) { var service = RabbitMQBootstrappService.Instance; service.BootstrappAction += (ctx) => { RabbitMQClient.s_configuration = configuration ?? RabbitMQServerConfiguration.Default; if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC)) { bootstrapper.AddIoCRegistrations( new TypeRegistration(typeof(RabbitMQServer), typeof(RabbitMQServer)), new InstanceTypeRegistration(configuration ?? RabbitMQServerConfiguration.Default, typeof(RabbitMQServerConfiguration), typeof(AbstractBaseConfiguration))); RegisterRabbitClientWithinContainer(bootstrapper); } }; if (!bootstrapper.RegisteredServices.Any(s => s == service)) { bootstrapper.AddService(service); } return(bootstrapper); }
/// <summary> /// Use EF Core as EventStore for system, with the provided connection string. /// This is a usable case for common cases, in system that not have a huge amount of events, or for test/debug purpose. /// This is not recommanded for real-world big applications case. /// </summary> /// <param name="bootstrapper">Bootstrapper instance.</param> /// <param name="options">Options to use to configure event store.</param> /// <returns>Bootstrapper instance</returns> public static Bootstrapper UseEFCoreAsEventStore(this Bootstrapper bootstrapper, EFEventStoreOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } var service = new EFEventStoreBootstrappService { BootstrappAction = (ctx) => { if (ctx.IsServiceRegistered(BootstrapperServiceType.IoC)) { bootstrapper.AddIoCRegistration(new FactoryRegistration(() => new EventStoreDbContext(options.DbContextOptions, options.ArchiveBehavior), typeof(EventStoreDbContext))); bootstrapper.AddIoCRegistration(new TypeRegistration(typeof(EFEventStore), true)); bootstrapper.AddIoCRegistration(new InstanceTypeRegistration(options, typeof(EFEventStoreOptions))); if (options.SnapshotBehaviorProvider != null) { bootstrapper.AddIoCRegistration( new InstanceTypeRegistration(options.SnapshotBehaviorProvider, typeof(ISnapshotBehaviorProvider))); } if (options.ArchiveBehavior == EventStore.SnapshotEventsArchiveBehavior.StoreToNewDatabase && options.ArchiveDbContextOptions != null) { bootstrapper.AddIoCRegistration(new FactoryRegistration(() => new ArchiveEventStoreDbContext(options.ArchiveDbContextOptions), typeof(ArchiveEventStoreDbContext))); } } EventStoreManager.s_Options = options; EventStoreManager.Activate(); } }; bootstrapper.AddService(service); return(bootstrapper); }
/// <summary> /// Use CosmosDB DocumentDB with a one or multiple server urls. /// Multiples urls are usefull when a replica set has been created. /// </summary> /// <param name="bootstrapper">Bootstrapper instance.</param> /// <param name="endPointUrl">Url of CosmosDB host server.</param> /// <param name="primaryKey">DataBase primary key</param> /// <returns>Bootstrapper instance.</returns> public static Bootstrapper UseCosmosDbAsEventStore(this Bootstrapper bootstrapper, string endPointUrl, string primaryKey) { if (string.IsNullOrEmpty(endPointUrl)) { throw new ArgumentNullException("BootstrapperExtensions.UseCosmosDbAsEventStore : endPointUrl have to be definied to use CosmosDb Event Store.", nameof(endPointUrl)); } if (string.IsNullOrEmpty(primaryKey)) { throw new ArgumentNullException("BootstrapperExtensions.UseCosmosDbAsEventStore : primarykey have to be definied to use CosmosDb Event Store.", nameof(primaryKey)); } var service = new CosmosDbEventStoreBootstrappService { BootstrappAction = (ctx) => { EventStoreAzureDbContext.Activate(new AzureDbConfiguration(endPointUrl, primaryKey)) .GetAwaiter().GetResult(); } }; bootstrapper.AddService(service); return(bootstrapper); }