private static BoundedContextManager CreateBoundedContextManager(IServiceCollection services, MiriworkConfiguration miriworkConfiguration, Type[] boundedContextTypes) { var boundedContextManager = new BoundedContextManager(miriworkConfiguration); boundedContextManager.Init(boundedContextTypes); services.AddSingleton <IMiriBoundedContextsAccessor>(boundedContextManager); return(boundedContextManager); }
private static RequestContextManager CreateRequestContextAccessor(IServiceCollection services, BoundedContextManager boundedContextManager, RequestIdFromHttpContextProvider requestIdFromHttpContextAccessor, ServiceProvider serviceProvider) { RequestCollections requestCollections = boundedContextManager.CreateRequestCollections(); var requestContextManager = new RequestContextManager(serviceProvider.GetService <IHttpContextAccessor>(), requestIdFromHttpContextAccessor, requestCollections.Request2BoundedContextId, requestCollections.Request2RequestMetadata); services.AddSingleton <IRequestContextAccessor>(requestContextManager); return(requestContextManager); }
private static void AddMiriServiceBus(IServiceCollection services, BoundedContextManager boundedContextManager, RequestContextManager requestContextManager, ServiceProvider tempServiceProvider) { Dictionary <Type, Type> requestType2ApplicationServiceType = new Dictionary <Type, Type>(); foreach (RequestMetadata requestMetadata in boundedContextManager.AllRequestMetadata) { if (!requestType2ApplicationServiceType.ContainsKey(requestMetadata.RequestType)) { requestType2ApplicationServiceType.Add(requestMetadata.RequestType, requestMetadata.ApplicationServiceType); } } MiriServiceBus serviceBus = new MiriServiceBus(tempServiceProvider.GetService <IHttpContextAccessor>(), requestContextManager, requestType2ApplicationServiceType); services.AddSingleton <IMiriServiceBus>(serviceBus); }
private static void RegisterDependenciesOfBoundedContexts(IServiceCollection services, MiriworkConfiguration miriworkConfiguration, BoundedContextManager boundedContextManager) { if (miriworkConfiguration?.DependenciesRegistrationType == DependenciesRegistrationType.DependenciesRegisteredByApplication) { return; } foreach (IMiriBoundedContext boundedContext in boundedContextManager.BoundedContexts) { RegistrationResult registrationResult = boundedContext.RegisterDependencies(services); if (registrationResult.ResultType == RegistrationResultType.ReturnedDependenciesModuleToRegister) { throw new ArgumentException("Cannot register unknown dependencies module in Miriwork." + Environment.NewLine + "Perhaps wrong value for MiriworkConfiguration.DependenciesRegistrationType?"); } } }
private static void RegisterApplicationServicesOfBoundedContexts(IServiceCollection services, MiriworkConfiguration miriworkConfiguration, BoundedContextManager boundedContextManager) { if (miriworkConfiguration?.RegisterApplicationServicesByMiriwork == false) { return; } var applicationServiceTypes = boundedContextManager.AllRequestMetadata.Select(m => m.ApplicationServiceType).Distinct(); foreach (Type serviceType in applicationServiceTypes) { services.AddTransient(serviceType); } }