Created
January 24, 2018 16:25
-
-
Save saurabhpati/76879d09487046a1a8a6da629280d88f to your computer and use it in GitHub Desktop.
CreateDefaulterBuilder Method.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IWebHostBuilder CreateDefaultBuilder(string[] args) | |
{ | |
var builder = new WebHostBuilder() | |
.UseKestrel((builderContext, options) => | |
{ | |
options.Configure(builderContext.Configuration.GetSection("Kestrel")); | |
}) | |
.UseContentRoot(Directory.GetCurrentDirectory()) | |
.ConfigureAppConfiguration((hostingContext, config) => | |
{ | |
var env = hostingContext.HostingEnvironment; | |
config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | |
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); | |
if (env.IsDevelopment()) | |
{ | |
var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); | |
if (appAssembly != null) | |
{ | |
config.AddUserSecrets(appAssembly, optional: 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(); | |
}); | |
if (args != null) | |
{ | |
builder.UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build()); | |
} | |
return builder; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment