-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServiceCollectionExtensions.cs
More file actions
152 lines (110 loc) · 5.06 KB
/
ServiceCollectionExtensions.cs
File metadata and controls
152 lines (110 loc) · 5.06 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Coravel;
using Tilework.Core.Interfaces;
using Tilework.LoadBalancing.Interfaces;
using Tilework.CertificateManagement.Interfaces;
using Tilework.LoadBalancing.Models;
using Tilework.LoadBalancing.Services;
using Tilework.LoadBalancing.Mappers;
using Tilework.LoadBalancing.Haproxy;
using Tilework.CertificateManagement.Services;
using Tilework.CertificateManagement.Mappers;
using Tilework.CertificateManagement.Models;
using Tilework.Core.Persistence;
using Tilework.Core.Commands;
using Tilework.Monitoring.Interfaces;
using Tilework.Monitoring.Telegraf;
using Tilework.Monitoring.Models;
using Tilework.Monitoring.Services;
using Tilework.Monitoring.Influxdb;
using Tilework.TokenVault.Services;
using Tilework.Persistence.IdentityManagement.Models;
using Tilework.IdentityManagement.Services;
using Tilework.Core.Jobs.CertificateManagement;
using Tilework.Events;
namespace Tilework.Core.Services;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddCoreServices(this IServiceCollection services,
Action<DbContextOptionsBuilder> dbContextOptions)
{
services.AddDbContext<TileworkContext>(dbContextOptions);
services.AddSingleton<IServiceManager, SystemdServiceManager>();
services.AddSingleton<IContainerManager, DockerServiceManager>();
services.AddSingleton<HttpApiFactoryService>();
services.AddHostedService<CoreInitializer>();
services.AddScoped<TokenService>();
services.AddScheduler();
services.AddQueue();
services.AddEvents();
return services;
}
public static IServiceCollection AddMonitoring(this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<DataCollectorConfiguration>(configuration.GetSection("DataCollector"));
services.Configure<DataPersistenceConfiguration>(configuration.GetSection("DataPersistence"));
services.AddScoped<IDataCollectorConfigurator, TelegrafConfigurator>();
services.AddScoped<IDataPersistenceConfigurator, Influxdb2Configurator>();
services.AddScoped<DataCollectorService>();
services.AddScoped<MonitoringService>();
services.AddHostedService<MonitoringInitializer>();
return services;
}
public static IServiceCollection AddLoadBalancing(this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<LoadBalancerConfiguration>(configuration);
services.AddAutoMapper(_ => { },
typeof(HAProxyConfigurationProfile),
typeof(HAProxyMonitoringProfile),
typeof(LoadBalancingMappingProfile));
services.AddScoped<ILoadBalancerService, LoadBalancerService>();
services.AddScoped<HAProxyConfigurator>();
services.AddHostedService<LoadBalancingInitializer>();
services.AddTransient<LoadBalancerCertificateListener>();
return services;
}
public static IServiceCollection AddCertificateManagement(this IServiceCollection services,
IConfiguration configuration)
{
services.Configure<CertificateManagementConfiguration>(configuration);
services.AddScoped<ICertificateManagementService, CertificateManagementService>();
services.AddScoped<AcmeProvider>();
services.AddScoped<AcmeVerificationService>();
services.AddHostedService<CertificateManagementInitializer>();
services.AddAutoMapper(_ => { }, typeof(CertificateManagementMappingProfile));
services.AddTransient<CertificateRenewalJob>();
return services;
}
public static IServiceCollection AddIdentityManagement(this IServiceCollection services,
IConfiguration configuration)
{
services.AddIdentityCore<User>(options =>
{
options.User.RequireUniqueEmail = true;
})
.AddRoles<Role>()
.AddEntityFrameworkStores<TileworkContext>();
services.Configure<IdentityOptions>(options =>
{
options.Lockout.AllowedForNewUsers = true;
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(10);
options.Lockout.MaxFailedAccessAttempts = 5;
options.Password.RequiredLength = 8;
});
services.AddScoped<UserService>();
return services;
}
public static IServiceCollection AddCommands(this IServiceCollection services)
{
services.AddScoped<ICommand, PrintVersionInfoCommand>();
services.AddScoped<ICommand, CreateUserCommand>();
services.AddScoped<ICommand, ResetPasswordCommand>();
services.AddScoped<CommandRunner>();
return services;
}
}