Пример #1
0
        public static IWebHostBuilder CreateHostBuilder(string[] args)
        {
            var buider = new WebHostBuilder()
                         .UseKestrel()
                         .UseStartup <Startup>()
                         .UseContentRoot(Directory.GetCurrentDirectory())
                         .ConfigureAppConfiguration((hostingContext, config) =>
            {
                var env = hostingContext.HostingEnvironment;
                config.AddJsonFile("appsettings.json", true, true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", true, true);
                //if (env.IsDevelopment())
                //{
                //    var appAssembly = Assembly.Load(new AssemblyName(env.EnvironmentName));
                //    if (appAssembly != null)
                //    {
                //        config.AddUserSecrets(appAssembly, true);
                //    }
                //}
                config.AddEnvironmentVariables();
                if (args != null)
                {
                    config.AddCommandLine(args);
                }
            })
                         .ConfigureLogging((hostingContext, Logging) =>
            {
                Logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                Logging.AddConsole();
                Logging.AddDebug();
            })
                         .UseIISIntegration()
                         .UseDefaultServiceProvider((Context, Options) =>
            {
                Options.ValidateScopes = Context.HostingEnvironment.IsDevelopment();
            });

            return(buider);
        }