-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
56 lines (48 loc) · 1.63 KB
/
Copy pathProgram.cs
File metadata and controls
56 lines (48 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using DutchTreat.Data;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.DependencyInjection;
namespace DutchTreat
{
public class Program
{
public static void Main(string[] args)
{
var host = BuildWebHost(args);
RunSeeding(host);
host.Run();
}
private static void RunSeeding(IWebHost host)
{
var scopeFactory = host.Services.GetService<IServiceScopeFactory>();
using (var scope = scopeFactory.CreateScope())
{
var seeder = host.Services.GetService<DutchSeeder>();
seeder.SeedAsync().Wait();
}
}
public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(SetupConfiguration)
.UseStartup<Startup>()
.Build();
private static void SetupConfiguration(WebHostBuilderContext context, IConfigurationBuilder builder)
{
//remove default configuration option
builder.Sources.Clear();
//configuration is loaded from multiple sources
//the hierarchy is in the same order as the source is added
//i.e variable from Environment will override the one from xml file which will override the one from Json file
builder.AddJsonFile("config.json", false, true)
.AddXmlFile("config.xml", true)
.AddEnvironmentVariables();
}
}
}