コード例 #1
0
 public static IModulesHostBuilder ConfigureWebHostDefaults(this IModulesHostBuilder builder, Action <Microsoft.AspNetCore.Hosting.IWebHostBuilder> configure)
 {
     return(builder.UseAspNetCoreWithDefaults((module, webHostBuilder) =>
     {
         configure(webHostBuilder);
     }));
 }
コード例 #2
0
 public static Task RunModule(this IModulesHostBuilder hostBuilder,
                              Type moduleType,
                              Action <IModuleHostingOptions> options = null)
 {
     hostBuilder.HostModule(moduleType, options);
     return(hostBuilder.Build().RunAsync());
 }
コード例 #3
0
        public static IModulesHostBuilder UseAspNetCoreWithDefaults(this IModulesHostBuilder builder, Action <IWebModule, Microsoft.AspNetCore.Hosting.IWebHostBuilder> configure = null)
        {
            builder.ConfigureFrameworkServices((ctx, services) =>
            {
                services
                .TryAddTransient <IWebModuleWebHostBuilderInitializer, WebModuleWebHostBuilderInitializerWithDefaults
                                  >();
            });

            return(UseAspNetCore(builder, configure));
        }
コード例 #4
0
        public static IModulesHostBuilder UseSimpleInjector(this IModulesHostBuilder hostBuilder)
        {
            hostBuilder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddTransient(typeof(IModuleContextFactory <>), typeof(ModuleContextFactory <>));
                services.AddTransient(typeof(IModuleServicesFilter), typeof(AddSimpleInjectorModuleServicesFilter));
                services.AddTransient(typeof(IBootstrapHostFilter <>), typeof(BootstrapHostFilter <>));
            });

            return(hostBuilder);
        }
コード例 #5
0
        /// <summary>
        /// Adds services to the container. This can be called multiple times and the results will be additive.
        /// </summary>
        /// <param name="hostBuilder"></param>
        /// <param name="configureDelegate">The delegate for configuring the <see cref="IServiceCollection"/> that will be used
        /// to construct the <see cref="IServiceProvider"/>.</param>
        /// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns>
        public static IModulesHostBuilder ConfigureServices(
            this IModulesHostBuilder hostBuilder,
            Action <IModulesHostBuilderContext, IServiceCollection> configureDelegate)
        {
            hostBuilder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddTransient <IModuleServicesFilter>(sp =>
                                                              new DelegateModuleServicesFilter(configureDelegate));
            });

            return(hostBuilder);
        }
コード例 #6
0
        public static IModulesHostBuilder ConfigureAspNetCore(this IModulesHostBuilder builder, Action <IWebModule, Microsoft.AspNetCore.Hosting.IWebHostBuilder> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            builder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.TryAddTransient <IWebModuleWebHostBuilderFilter>(sp => new DelegateWebModuleWebHostBuilderFilter(configure));
            });

            return(builder);
        }
コード例 #7
0
        public static IModulesHostBuilder UseAspNetCore(this IModulesHostBuilder builder, Func <Microsoft.AspNetCore.Hosting.IWebHostBuilder> webHostBuilder, Action <IWebModule, Microsoft.AspNetCore.Hosting.IWebHostBuilder> configure = null)
        {
            if (webHostBuilder == null)
            {
                throw new ArgumentNullException(nameof(webHostBuilder));
            }

            builder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddTransient(typeof(IBootstrapHostFilter <>), typeof(WebModuleBootstrapHostFilter <>));
                services.TryAddTransient <IWebModuleWebHostBuilderFactory>(sp => new DelegateWebHostBuilderFactory(webHostBuilder));
            });

            return(ConfigureAspNetCore(builder, configure));
        }
コード例 #8
0
        public static IModulesHostBuilder UseAspNetCore(this IModulesHostBuilder builder,
                                                        Action <IWebModule, Microsoft.AspNetCore.Hosting.IWebHostBuilder> configure = null)
        {
            builder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddTransient(typeof(IBootstrapHostFilter <>), typeof(WebModuleBootstrapHostFilter <>));
                services.TryAddTransient <IWebModuleWebHostBuilderInitializer, WebModuleWebHostBuilderInitializer>();

                if (configure != null)
                {
                    services.AddTransient <IWebModuleWebHostBuilderFilter>(sp => new DelegateWebModuleWebHostBuilderFilter(configure));
                }
            });

            return(builder);
        }
コード例 #9
0
        // ReSharper disable once UnusedMethodReturnValue.Global
        public static IModulesHostBuilder UseSimpleInjector(this IModulesHostBuilder hostBuilder,
                                                            Container container, bool enableModuleContainer = true)
        {
            if (container.Options.DefaultScopedLifestyle == null)
            {
                container.Options.DefaultScopedLifestyle = new AsyncScopedLifestyle();
            }

            hostBuilder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddSingleton(container);
                services.AddTransient <IModuleHostServiceProviderFactory, ServiceProviderFactory>();
            });

            return(!enableModuleContainer
                ? hostBuilder
                : UseSimpleInjector(hostBuilder));
        }
コード例 #10
0
        public static IModulesHostBuilder AddIdentityModule(this IModulesHostBuilder builder, Container container)
        {
            builder.HostModule <IdentityModule>();

            builder.ConfigureFrameworkServices((ctx, services) =>
            {
                services.AddTransient <IConfigureContainerFilter <IdentityModule>, IdentityModuleFilters>();
                services.AddTransient <IModuleServicesFilter <IdentityModule>, IdentityModuleFilters>();
            });

            container.RegisterSingleton <IConfigReaderService <ClientConfigModel>, ClientConfigReaderService>();
            container.RegisterSingleton <IConfigWriterService <ClientConfigModel>, ClientConfigWriterService>();


            container.Register <IDbContextConfigurer <ConfigurationDbContext>, InMemoryConfigurationStoreContextConfigurer>();

            return(builder);
        }
コード例 #11
0
 public static Task RunModule <TModule>(this IModulesHostBuilder hostBuilder,
                                        Action <IModuleHostingOptions> options = null) where TModule : class
 {
     return(RunModule(hostBuilder, typeof(TModule), options));
 }
コード例 #12
0
 public static IModulesHostBuilder UseServiceCollection(this IModulesHostBuilder hostBuilder,
                                                        IServiceCollection services)
 {
     hostBuilder.UseServiceProviderFactory(new ServiceCollectionServiceProviderFactory(services));
     return(hostBuilder);
 }