Пример #1
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)

                   // .UseWindowsService()
                   .ConfigureServices((hostContext, services) => { services.AddHostedService <Worker>(); }));
        }
Пример #2
0
        public static IHost CreateHostBuilder(string[] args)
        {
            Log.Logger = SetupSerilog(Configuration);

            // Build the host
            var host = MsHost.CreateDefaultBuilder(args)
                       .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                       .ConfigureLogging(SetupLogging)
                       .UseSerilog(dispose: true)
                       .ConfigureWebHostDefaults(wb => wb
                                                 .UseStartup <Startup>(hostingContext =>
            {
                hostingContext.Configuration = Configuration;
                var startupLogger            = new SerilogLoggerFactory(Log.Logger).CreateLogger("File");
                return(new Startup(hostingContext, startupLogger));
            }))
                       .Build();

            // At this stage - after ConfigureServices & ConfigureContainer have been called - we can access IServiceProvider.
            var appContext        = host.Services.GetRequiredService <IApplicationContext>();
            var providerContainer = (appContext as IServiceProviderContainer)
                                    ?? throw new ApplicationException($"The implementation of '${nameof(IApplicationContext)}' must also implement '${nameof(IServiceProviderContainer)}'.");

            providerContainer.ApplicationServices = host.Services;

            // At this stage we can set the scoped service container.
            var engine = host.Services.GetRequiredService <IEngine>();

            engine.Scope = new ScopedServiceContainer(
                host.Services.GetRequiredService <ILifetimeScopeAccessor>(),
                host.Services.GetRequiredService <IHttpContextAccessor>(),
                host.Services.AsLifetimeScope());

            return(host);
        }
Пример #3
0
 public static IHostBuilder CreateHostBuilder(string[] args)
 {
     return(HostingHost.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
     {
         webBuilder.UseStartup <Startup>();
     }));
 }
Пример #4
0
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 WebHost.CreateDefaultBuilder(args)
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder
     .UseStartup <Startup>()
     .UseSerilog();
 });
 public static IHostBuilder CreateHostBuilder(string[] args) => HostBuilder
 .CreateDefaultBuilder(args)
 .UseWindowsService()
 .UseSerilog(ConfigureSerilog)
 .ConfigureWebHostDefaults(webBuilder => webBuilder
                           .ConfigureAppConfiguration(_ => ConfigureAppConfiguration(_, args))
                           .ConfigureKestrel(ConfigureKestrel)
                           .UseStartup <Startup>()
                           );
Пример #6
0
 /// <summary>
 /// 创建 HostBuilder
 /// </summary>
 /// <param name="args"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration configuration)
 {
     return(WebHost.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
     {
         webBuilder.UseStartup <Startup>();
     })
            .ConfigureAppConfiguration(x => x.AddConfiguration(configuration))
            .UseSerilog());
 }
Пример #7
0
 /// <summary>
 /// Host environment builder
 /// </summary>
 /// <param name="args">Arguments list</param>
 public static IHostBuilder CreateHostBuilder(string[] args) =>
 MsHost.CreateDefaultBuilder(args)
 .ConfigureLogging(logging =>
 {
     logging.ClearProviders();
     logging.AddConsoleLogger();
     logging.AddSeqLogger();
 })
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder.UseStartup <Startup>();
 });
 /// <summary>
 /// 创建主机
 /// </summary>
 /// <param name="args"></param>
 /// <returns></returns>
 internal static IHostBuilder CreateHostBuilder(string[] args) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder.UseConfiguration(
         new ConfigurationBuilder()
         .SetBasePath(Environment.CurrentDirectory)
         .AddJsonFile("host.json")
         .Build()
         );
     webBuilder.UseStartup <Startup>();
 })
 .UseSerilog();
Пример #9
0
        private static IHostBuilder CreateHostBuilder(String[] args, IConfiguration config, ILogger logger) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((_, services)
                           => services.AddHostedService(_ => BuildService(config, logger)))
        .ConfigureLogging((context, builder) =>
        {
            // configure Logging with NLog
            builder.ClearProviders();

            var section = context.Configuration.GetSection("NLog");
            var cfg     = new NLogLoggingConfiguration(section);
            builder.AddNLog(cfg);
        })
        .UseWindowsService();
 /// <summary>
 /// The method to create and build the host.
 /// </summary>
 /// <param name="args">The arguments of configuration.</param>
 /// <returns></returns>
 public static IHost CreateHostBuilder(string[] args) =>
 HostBuilder
 .CreateDefaultBuilder(args)
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder
     .UseKestrel(options =>
     {
         options.Limits.MaxRequestBodySize  = null;
         options.Limits.MinResponseDataRate = null;
     })
     .ConfigureAppConfiguration((hostingContext, configuration) => hostingContext.ConfigAppSettingsFiles(configuration))
     .UseStartup <Startup>();
 })
 .Build();
Пример #11
0
 public static IHostBuilder CreateHostBuilder(string[] args)
 {
     return(Host.CreateDefaultBuilder(args)
            .UseServiceProviderFactory(new AutofacServiceProviderFactory())
            .ConfigureContainer <ContainerBuilder>(builder =>
     {
         builder.RegisterModule(new BusinessLogicModule());
         builder.RegisterModule(new MainServerModule());
         // builder.Populate(services);
     })
            .ConfigureWebHostDefaults(webBuilder =>
     {
         webBuilder
         .UseUrls("http://*:" + xtradeConstants.WebBackend_PORT.ToString())
         .UseStartup <Startup>();
     }));
 }
Пример #12
0
        public static IHost CreateHostBuilder(string[] args)
        {
            Log.Logger = SetupSerilog(Configuration);

            return(MsHost.CreateDefaultBuilder(args)
                   .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                   .ConfigureLogging(SetupLogging)
                   .UseSerilog(dispose: true)
                   .ConfigureWebHostDefaults(wb => wb
                                             .UseStartup <Startup>(hostingContext =>
            {
                hostingContext.Configuration = Configuration;
                var startupLogger = new SerilogLoggerFactory(Log.Logger).CreateLogger("File");
                return new Startup(hostingContext, startupLogger);
            }))
                   .Build());
        }
Пример #13
0
        private static IHost BuildHost()
        {
            return(GenericHost.CreateDefaultBuilder()
                   .ConfigureServices((hostContext, services) =>
            {
                services.AddDbContext <AvalancheDbContext>(options =>
                                                           options
                                                           .EnableSensitiveDataLogging()
                                                           .EnableDetailedErrors()
                                                           .UseSqlServer(hostContext.Configuration.GetConnectionString("Avalanche")));

                services.Configure <ArmaghanCredentials>(hostContext.Configuration.GetSection("Armaghan"));
                services.Configure <BulkOptions>(hostContext.Configuration.GetSection("BulkOptions"));

                services.AddHostedService <SenderHostedService>();
            })
                   .Build());
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)

                   .UseServiceProviderFactory(new AutofacServiceProviderFactory(buolder =>
            {
                buolder.RegisterModule(new AutofacModule());
            }))
                   .UseContentRoot(Directory.GetCurrentDirectory())
                   .ConfigureHostConfiguration(builder =>
            {
                builder.AddInMemoryCollection()
                .AddJsonFile(@".Config\appsettings.json", optional: false, reloadOnChange: true)
                .AddJsonFile(@".Config\ConnectionString.json", optional: false, reloadOnChange: true)
                .AddJsonFile(@".Config\APILTEUrl.json", optional: false, reloadOnChange: true)
                .AddEnvironmentVariables();

                var Configuration = builder.Build();

                GVariable.configuration = Configuration;
            })
                   .ConfigureServices(services =>
            {
                services.AddAutofac(c =>
                {
                    c.Populate(services);
                });

                services.AddDbContextPool <CoreContextDIP>((opt) =>
                {
                }, 100);

                #region MassTransit

                services.AddMassTransit(x =>
                {
                    #region Event

                    x.AddConsumer <RoleDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);
                    }));

                    x.AddConsumer <PageRouteDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);
                    }));

                    x.AddConsumer <AccountDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);
                    }));

                    x.AddConsumer <CaptchaDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);
                        //r.Immediate(5); //Incremental
                    }));

                    x.AddConsumer <AppInfoDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);           //Incremental
                    }));

                    x.AddConsumer <AssetDomainEvent>(c => c.UseMessageRetry(r =>
                    {
                        r.Immediate(5);           //Incremental
                    }));

                    #endregion


                    x.SetKebabCaseEndpointNameFormatter();

                    x.UsingRabbitMq((ctx, cfg) =>
                    {
                        string mqHostAddress = GVariable.configuration["MTMQ:Host"];

                        cfg.Host(mqHostAddress, virtualHost: "/", c =>
                        {
                            var user = GVariable.configuration["MTMQ:UserName"];
                            var pwd = GVariable.configuration["MTMQ:Password"];

                            c.Username(user);
                            c.Password(pwd);
                        });

                        cfg.ConfigureEndpoints(ctx);
                    });
                });

                services.AddMassTransitHostedService();
                services.AddWorkflow();
                #endregion
            }));

            //.ConfigureAppConfiguration;
        }
Пример #15
0
 /// <summary>Creates the host builder for the application.</summary>
 /// <returns>A host builder.</returns>
 public virtual IHostBuilder CreateHostBuilder() => Host.CreateDefaultBuilder();
Пример #16
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        //for a list of things CreateDefaultBuilder does see:
        // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/web-host?view=aspnetcore-3.0
        AppHost
        .CreateDefaultBuilder(args)
        .UseContentRoot(Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location))
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            //default application name is assembly name, override to friendlier name
            hostingContext.HostingEnvironment.ApplicationName = "Gamp.Weather";

            // CreateDefaultBuilder adds configuration in this order:
            //  appsettings.json.
            //  appsettings.{ Environment}.json.
            //  Secret Manager when the app runs in the Development environment using the entry assembly.
            //  Environment variables.
            //  Command - line arguments.
            if (File.Exists($"{hostingContext.HostingEnvironment.ContentRootPath}\\appsettings.User.json"))
            {
                // Add a user file (excluded from source) after all other sources to allow developers to
                // override settings locally without playing tug-of-war with tracked source config files
                config.AddJsonFile("appsettings.User.json", true);
            }
        })
        .ConfigureServices((hostContext, services) =>
        {
            // Configure options for kestrel self-hosting from IConfiguration
            // Note: This will override local launchSettings.json values
            services.Configure <KestrelServerOptions>(
                hostContext.Configuration.GetSection("Kestrel"));

            var mode = hostContext.Configuration.GetValue("WeatherStore", "Sql");

            // Add a Worker Service to run the auto-migrator
            // See the docs for more informaion on Worker Services
            // https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-3.0&tabs=visual-studio

            switch (mode.ToLowerInvariant())
            {
            case "sql":
                services.AddWeatherDbContextMigrator(
                    hostContext.Configuration.GetConnectionString("WeatherSqlContext"));
                break;

            case "mongo":
                services.AddWeatherMongoMigrator(hostContext.Configuration.GetConnectionString("WeatherMongoDb"));
                break;

            default:
                //no migrator for memory or others
                break;
            }
        })
        .UseSerilog((hostingContext, loggerConfiguration) =>
        {
            //get serilog settings from IConfiguration
            loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
        })
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup <Startup>();
        });
Пример #17
0
 private static IHostBuilder CreateHostBuilder(String[] args, IConfiguration config, ILogger logger) =>
 Host.CreateDefaultBuilder(args)
 .ConfigureServices((hostContext, services)
                    => services.AddHostedService(_ => BuildService(config, logger)))
 .ConfigureLifeTime();
Пример #18
0
 private static IHostBuilder CreateHostBuilder(string[] args) =>
 AspNetHost.CreateDefaultBuilder(args)
 .ConfigureWebHostDefaults(webBuilder =>
 {
     webBuilder.UseStartup <Startup>();
 });