forked from topnguyen/Elect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
44 lines (33 loc) · 1.06 KB
/
Program.cs
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
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace Elect.Sample.DI
{
public class Program
{
public static void Main(string[] args)
{
IWebHost webHost = BuildWebHost(args);
OnAppStart(webHost);
webHost.Run();
}
public static IWebHost BuildWebHost(string[] args)
{
var webHostBuilder = WebHost.CreateDefaultBuilder(args);
webHostBuilder.UseStartup<Startup>();
var webHost = webHostBuilder.Build();
return webHost;
}
private static void OnAppStart(IWebHost webHost)
{
using (var scope = webHost.Services.CreateScope())
{
var serviceProvider = scope.ServiceProvider;
var sampleService = serviceProvider.GetService<Startup.ISampleService>();
var token = sampleService.GetRandomString();
Console.WriteLine(token);
}
}
}
}