Last active
November 8, 2019 19:04
-
-
Save Tylerian/9d0b9144f7be9bc0e5d6d6cfac91c053 to your computer and use it in GitHub Desktop.
Vanilla AspNetCore
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.IO; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
namespace Vanilla | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) => | |
CreateHostBuilder(args).RunConsoleAsync(); | |
static IHostBuilder CreateHostBuilder(string[] args) => | |
// THIS IS THE SAME AS CALLING Host.CreateDefaultBuilder().ConfigureAppConfig(config => config.AddJsonFile("config.json")); | |
new HostBuilder() | |
.ConfigureLogging(logging => { | |
logging.AddConsole(); | |
}) | |
.ConfigureServices(ConfigureServices) | |
.ConfigureAppConfiguration(config => { | |
config.AddJsonFile("config.json", optional: true); | |
config.AddEnvironmentVariables(); | |
}) | |
.ConfigureHostConfiguration(config => { | |
config.AddEnvironmentVariables(prefix: "DOTNET_"); | |
config.AddCommandLine(args); | |
}) | |
.UseContentRoot(Directory.GetCurrentDirectory()); | |
// .UseDefaultServiceProvider(config => { | |
// THIS ONLY SETS ENV BASED CONFIG TO THE ALREADY PROVIDED SvcPrvdr | |
// }); | |
} | |
} |
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.IO; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
namespace Vanilla | |
{ | |
public class Program | |
{ | |
static void Main(string[] args) => | |
CreateHostBuilder(args).RunConsoleAsync(); | |
static IHostBuilder CreateHostBuilder(string[] args) => | |
// THIS IS THE SAME AS CALLING Host.CreateDefaultBuilder().ConfigureAppConfig(config => config.AddJsonFile("config.json")); | |
new HostBuilder() | |
.ConfigureLogging(logging => { | |
logging.AddConsole(); | |
}) | |
.ConfigureAppConfiguration(config => { | |
config.AddJsonFile("config.json", optional: true); | |
config.AddEnvironmentVariables(); | |
}) | |
.ConfigureHostConfiguration(config => { | |
config.AddEnvironmentVariables(prefix: "DOTNET_"); | |
config.AddCommandLine(args); | |
}) | |
.UseContentRoot(Directory.GetCurrentDirectory()) | |
// .UseDefaultServiceProvider(config => { | |
// THIS ONLY SETS ENV BASED CONFIG TO THE ALREADY PROVIDED SvcPrvdr | |
// }); | |
// This Wraps HostBuilder into GenericWebHostBuilder and | |
// adds GenericWebHostService as a HostedService to the HostBuilder | |
.ConfigureWebHost(webhost => { | |
webhost | |
.UseKestrel() | |
.Either(Configure(appBuilder => { })).Or(UseStartUp<StartUpClass>()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment