-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (46 loc) · 1.96 KB
/
Program.cs
File metadata and controls
58 lines (46 loc) · 1.96 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
57
58
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using XePlatformAuthentication.Helpers;
using XePlatformAuthentication.Models;
using XePlatformAuthentication.Services;
using XePlatformAuthentication.Services.Interfaces;
namespace XePlatformAuthentication
{
internal class Program
{
private static async Task Main()
{
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
var configuration = SetupConfiguration();
var services = new ServiceCollection();
var appSettings = configuration.GetSection("AppSettings").Get<AppSettings>();
services.AddSingleton(appSettings);
services.AddSingleton<IJwtClient, JwtClient>();
services.AddSingleton<IEntriesClient, EntriesClient>();
services.AddSingleton<ITokenCache, TokenCache>();
services.AddSingleton<Runner>();
var container = services.BuildServiceProvider();
var runner = container.GetService<Runner>();
await runner.Run();
}
private static IConfiguration SetupConfiguration()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile($"appsettings.{EnvironmentExtensions.GetEnvironment()}.json", false)
.AddEnvironmentVariables()
.Build();
}
private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
var exception = e.ExceptionObject as Exception;
if (exception is AggregateException aggregateException)
exception = aggregateException.Flatten();
Console.WriteLine($"Global exception handler caught unexpected error: {exception}");
Environment.Exit(1);
}
}
}