-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
55 lines (48 loc) · 1.64 KB
/
Copy pathProgram.cs
File metadata and controls
55 lines (48 loc) · 1.64 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
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace DigitalWellbeing
{
class Program
{
static void Main()
{
var host = new HostBuilder()
.ConfigureAppConfiguration((context, config) =>
{
config.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
})
.ConfigureServices((context, services) =>
{
services.AddSingleton<IConfiguration>(context.Configuration);
services.AddSingleton<Configuration>();
services.AddSingleton<Utils>();
services.AddSingleton<DBStorage>();
services.AddSingleton<Logger>();
services.AddSingleton<Listener>();
services.AddHostedService<ListenerHostedService>();
})
.UseConsoleLifetime()
.Build();
host.Run();
}
}
public class ListenerHostedService : IHostedService
{
private readonly Listener _listener;
public ListenerHostedService(Listener listener)
{
_listener = listener;
}
public Task StartAsync(CancellationToken cancellationToken)
{
_listener.Start();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
}