Skip to content

Commit

Permalink
refactor: switch to top level registration
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Jul 15, 2024
1 parent 4440a23 commit 33cf31e
Showing 1 changed file with 42 additions and 46 deletions.
88 changes: 42 additions & 46 deletions Hammer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,45 @@
#endif
.CreateLogger();

await Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder => builder.AddJsonFile("data/config.json", true, true))
.ConfigureLogging(builder =>
{
builder.ClearProviders();
builder.AddSerilog();
})
.ConfigureServices(services =>
{
services.AddSingleton(new DiscordClient(new DiscordConfiguration
{
Token = Environment.GetEnvironmentVariable("DISCORD_TOKEN"),
LoggerFactory = new SerilogLoggerFactory(),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.GuildMembers | DiscordIntents.MessageContents
}));
services.AddDbContextFactory<HammerContext>();
services.AddHostedSingleton<DatabaseService>();
services.AddSingleton<HttpClient>();
services.AddSingleton<ConfigurationService>();
services.AddSingleton<InfractionStatisticsService>();
services.AddSingleton<MailmanService>();
services.AddSingleton<MessageService>();
services.AddSingleton<MessageDeletionService>();
services.AddSingleton<WarningService>();
services.AddHostedService<StaffReactionService>();
services.AddHostedService<UserReactionService>();
services.AddHostedSingleton<AltAccountService>();
services.AddHostedSingleton<BanService>();
services.AddHostedSingleton<DiscordLogService>();
services.AddHostedSingleton<InfractionService>();
services.AddHostedSingleton<InfractionCooldownService>();
services.AddHostedSingleton<MemberNoteService>();
services.AddHostedSingleton<MessageReportService>();
services.AddHostedSingleton<MessageTrackingService>();
services.AddHostedSingleton<MuteService>();
services.AddHostedSingleton<RuleService>();
services.AddHostedSingleton<BotService>();
})
.UseConsoleLifetime()
.RunConsoleAsync();
HostApplicationBuilder builder = Host.CreateApplicationBuilder(args);
builder.Configuration.AddJsonFile("data/config.json", true, true);

builder.Logging.ClearProviders();
builder.Logging.AddSerilog();

builder.Services.AddSingleton(new DiscordClient(new DiscordConfiguration
{
Token = Environment.GetEnvironmentVariable("DISCORD_TOKEN"),
LoggerFactory = new SerilogLoggerFactory(),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.GuildMembers | DiscordIntents.MessageContents
}));

builder.Services.AddDbContextFactory<HammerContext>();
builder.Services.AddHostedSingleton<DatabaseService>();

builder.Services.AddSingleton<HttpClient>();
builder.Services.AddSingleton<ConfigurationService>();
builder.Services.AddSingleton<InfractionStatisticsService>();
builder.Services.AddSingleton<MailmanService>();
builder.Services.AddSingleton<MessageService>();
builder.Services.AddSingleton<MessageDeletionService>();
builder.Services.AddSingleton<WarningService>();

builder.Services.AddHostedService<StaffReactionService>();
builder.Services.AddHostedService<UserReactionService>();

builder.Services.AddHostedSingleton<AltAccountService>();
builder.Services.AddHostedSingleton<BanService>();
builder.Services.AddHostedSingleton<DiscordLogService>();
builder.Services.AddHostedSingleton<InfractionService>();
builder.Services.AddHostedSingleton<InfractionCooldownService>();
builder.Services.AddHostedSingleton<MemberNoteService>();
builder.Services.AddHostedSingleton<MessageReportService>();
builder.Services.AddHostedSingleton<MessageTrackingService>();
builder.Services.AddHostedSingleton<MuteService>();
builder.Services.AddHostedSingleton<RuleService>();

builder.Services.AddHostedSingleton<BotService>();

IHost app = builder.Build();
await app.RunAsync();

0 comments on commit 33cf31e

Please sign in to comment.