Last active
October 4, 2018 00:21
-
-
Save lazarofl/cc02069b2a3ece0e1536022e445cb1fa to your computer and use it in GitHub Desktop.
ASPNET Core MVC Program.cs to use appsettings json files and EnvironmentVariables configurations
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.Logging; | |
namespace workshop_mackenzie { | |
public class Program { | |
public static void Main (string[] args) { | |
CreateWebHostBuilder (args).Build ().Run (); | |
} | |
public static IWebHostBuilder CreateWebHostBuilder (string[] args) { | |
return WebHost.CreateDefaultBuilder (args) | |
.ConfigureAppConfiguration (ConfigConfiguration) | |
.UseStartup<Startup> (); | |
} | |
static void ConfigConfiguration (WebHostBuilderContext ctx, IConfigurationBuilder config) { | |
config.SetBasePath (Directory.GetCurrentDirectory ()) | |
.AddJsonFile ("appsettings.json", optional : false, reloadOnChange : true) | |
.AddJsonFile ($"appsettings.{ctx.HostingEnvironment.EnvironmentName}.json", optional : true, reloadOnChange : true) | |
.AddEnvironmentVariables (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment