-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
58 lines (48 loc) · 2.28 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using dan_client_dotnet.Config;
using dan_client_dotnet.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
namespace dan_client_dotnet
{
class Program
{
static async Task Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.Build();
HttpClientConfig clientConfig = new HttpClientConfig();
config.GetSection("HttpClientConfig").Bind(clientConfig);
CertificateConfig certificateConfig = new CertificateConfig();
config.GetSection("CertificateConfig").Bind(certificateConfig);
MaskinportenConfig maskinportenConfig = new MaskinportenConfig();
config.GetSection("MaskinportenConfig").Bind(maskinportenConfig);
var host = new HostBuilder()
.ConfigureServices((hostContext, services) =>
{
services.Configure<RequestConfig>(config.GetSection("RequestConfig"));
services.Configure<AccreditationConfig>(config.GetSection("Accreditation"));
services.Configure<MaskinportenConfig>(config.GetSection("MaskinportenConfig"));
services.Configure<CertificateConfig>(config.GetSection("CertificateConfig"));
services.AddTransient<RequestService>();
services.AddTransient<AccreditationService>();
services.AddTransient<MaskinportenService>();
services.AddHttpClient("", c =>
{
c.BaseAddress = new Uri(clientConfig.BaseAddress);
c.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", clientConfig.SubscriptionKey);
});
}).Build();
RequestService requestHandler = host.Services.GetRequiredService<RequestService>();
Console.WriteLine(await requestHandler.Demo());
await host.RunAsync();
}
}
}