-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.cs
More file actions
47 lines (43 loc) · 1.66 KB
/
Module.cs
File metadata and controls
47 lines (43 loc) · 1.66 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
using Hangfire;
using Hangfire.Console;
using Hangfire.PostgreSql;
using Logrus.Ext;
using Logrus.Smith.Data;
using Logrus.Smith.Infra;
using Logrus.Smith.Settings;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Logrus.Smith;
public class Module: IModule
{
public void RegisterServices(IServiceCollection services, IConfiguration configuration)
{
var dataSettings = services.AddSettings<LogrusSmithSettings>(configuration);
services.AddDbContext<AgentDbContext>(options =>
{
options.UseNpgsql(dataSettings.DbConnectionString);
}, ServiceLifetime.Transient);
services.AddSingleton<Func<AgentDbContext>>(sp => sp.GetRequiredService<AgentDbContext>);
services.AddTransient<AgentHypervisor>();
services.AddSingleton<AgentCallbackManager>();
services.AddHangfireServer();
services.AddHangfire(config =>
{
config.UsePostgreSqlStorage(c => c.UseNpgsqlConnection(dataSettings.DbConnectionString), new PostgreSqlStorageOptions()
{
InvisibilityTimeout = TimeSpan.FromHours(24),
});
config.UseConsole();
});
services.AddSingleton<DistributedLockFactory>();
}
public async Task RunServices(IServiceProvider services)
{
GlobalConfiguration.Configuration.UseActivator(new HangfireDiActivator(services));
var db = services.GetRequiredService<AgentDbContext>();
await db.Database.MigrateAsync();
var hypervisor = services.GetRequiredService<AgentHypervisor>();
hypervisor.Register();
}
}