Exemplo n.º 1
0
        public static void InitMiriwork(IMvcBuilder mvcbuilder, IServiceCollection services,
                                        MiriworkConfiguration miriworkConfiguration, Type[] boundedContextTypes)
        {
            // add memorycache to cache http-requests
            services.AddMemoryCache();

            // add the assembly as an application part so that MiriController can be found
            mvcbuilder.AddApplicationPart(Assembly.GetExecutingAssembly());

            // create and register the Miriwork-classes
            services.AddHttpContextAccessor();
            var tempServiceProvider   = services.BuildServiceProvider();
            var boundedContextManager = CreateBoundedContextManager(services, miriworkConfiguration,
                                                                    boundedContextTypes);
            var requestIdFromHttpContextAccessor = CreateRequestIdFromHttpContextProvider(tempServiceProvider);
            var requestContextManager            = CreateRequestContextAccessor(services, boundedContextManager,
                                                                                requestIdFromHttpContextAccessor, tempServiceProvider);

            AddMiriServiceBus(services, boundedContextManager, requestContextManager, tempServiceProvider);
            AddMiriModelBinderProviders(mvcbuilder, requestContextManager, tempServiceProvider);

            // register dependencies after registration of Miriwirk-classes
            RegisterDependenciesOfBoundedContexts(services, miriworkConfiguration, boundedContextManager);
            RegisterApplicationServicesOfBoundedContexts(services, miriworkConfiguration, boundedContextManager);
        }
Exemplo n.º 2
0
        private static BoundedContextManager CreateBoundedContextManager(IServiceCollection services,
                                                                         MiriworkConfiguration miriworkConfiguration, Type[] boundedContextTypes)
        {
            var boundedContextManager = new BoundedContextManager(miriworkConfiguration);

            boundedContextManager.Init(boundedContextTypes);

            services.AddSingleton <IMiriBoundedContextsAccessor>(boundedContextManager);

            return(boundedContextManager);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds Miriwork to Mvc component of Asp.Net Core with a MiriworkConfiguration.
 /// </summary>
 /// <param name="mvcbuilder">MvcBuilder of Asp.Net Core</param>
 /// <param name="services">ServiceCollection of Asp.Net Core</param>
 /// <param name="miriworkConfiguration">instance of MiriworkConfiguation</param>
 /// <param name="boundedContextTypes">types of bounded contexts, e.g. "typeof(Example.BoundedContext.Bar)"</param>
 public static void AddMiriwork(this IMvcBuilder mvcbuilder, IServiceCollection services,
                                MiriworkConfiguration miriworkConfiguration, params Type[] boundedContextTypes)
 {
     Bootstrapper.InitMiriwork(mvcbuilder, services, miriworkConfiguration, boundedContextTypes);
 }
Exemplo n.º 5
0
 public BoundedContextManager(MiriworkConfiguration miriworkConfiguration)
 {
     this.requestMetadataFactory = new RequestMetadataFactory(miriworkConfiguration?.RequestBaseType,
                                                              miriworkConfiguration?.ResponseBaseType, miriworkConfiguration?.ApplicationServiceBaseType);
 }
Exemplo n.º 6
0
        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?");
                }
            }
        }