-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
69 lines (52 loc) · 2.28 KB
/
Startup.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
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using System.IO;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Office365GmailMigratorChecker.Model;
using NLog.Extensions.Logging;
namespace Office365GmailMigratorChecker
{
class Startup
{
static void Main()
{
IServiceCollection serviceCollection = new ServiceCollection();
ConfigureServices(serviceCollection);
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
var app = serviceProvider.GetService<Application>();
Task.Run(() => app.Run()).GetAwaiter().GetResult();
Console.ReadKey();
}
private static void ConfigureServices(IServiceCollection services)
{
//add program configuration
IConfigurationRoot configuration = GetConfiguration();
services.AddSingleton<IConfigurationRoot>(configuration);
//separate my configuration settings please
services.AddOptions();
services.Configure<Gmail>(options => configuration.GetSection("Gmail").Bind(options));
services.Configure<Graph>(options => configuration.GetSection("Graph").Bind(options));
services.Configure<AppSettings>(options => configuration.Bind(options));
//and then my actual classes
services.AddTransient<Application>();
services.AddSingleton<GmailService>();
services.AddSingleton<GraphService>();
services.AddSingleton<SqlExpressService>();
services.AddScoped<LocalPersistanceService>();
services.AddScoped<MessageBatchFactory>();
ILoggerFactory loggerFactory = new LoggerFactory()
.AddNLog();
services.AddSingleton(loggerFactory); // Add first my already configured instance
services.AddLogging(); // Allow ILogger<T>*/
}
private static IConfigurationRoot GetConfiguration()
{
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange:true)
.Build();
}
}
}