-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: separate DI registration from startup (resolves #66)
- Loading branch information
1 parent
aeed851
commit 2a7a932
Showing
3 changed files
with
64 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using ModShark.Reports; | ||
using ModShark.Reports.Reporter; | ||
using ModShark.Rules; | ||
using ModShark.Services; | ||
using SharkeyDB; | ||
|
||
namespace ModShark; | ||
|
||
public static class ModSharkModule | ||
{ | ||
public static T AddModShark<T>(this T services, IConfiguration configuration) | ||
where T : IServiceCollection | ||
{ | ||
// Register dependencies first. | ||
// Order doesn't really matter, but it makes more sense conceptually. | ||
services.AddSharkeyDB(); | ||
|
||
// Read and register config. | ||
// This will be reworked later. | ||
var config = configuration | ||
.GetSection("ModShark") | ||
.Get<ModSharkConfig>() | ||
?? throw new ApplicationException("Configuration file is invalid: could not map to the config object."); | ||
services.AddSingleton(config.Postgres); | ||
services.AddSingleton(config.Sharkey); | ||
services.AddSingleton(config.Worker); | ||
services.AddSingleton(config.Reporters.SendGrid); | ||
services.AddSingleton(config.Reporters.Console); | ||
services.AddSingleton(config.Reporters.Native); | ||
services.AddSingleton(config.Reporters.Post); | ||
services.AddSingleton(config.Rules.FlaggedUser); | ||
services.AddSingleton(config.Rules.FlaggedInstance); | ||
services.AddSingleton(config.Rules.FlaggedNote); | ||
|
||
// Register all services. | ||
|
||
services.AddHttpClient<IHttpService, HttpService>(); | ||
services.AddScoped<ISharkeyHttpService, SharkeyHttpService>(); | ||
|
||
services.AddSingleton<IRandomService, RandomService>(); | ||
services.AddSingleton<ITimeService, TimeService>(); | ||
services.AddSingleton<ISharkeyIdService, SharkeyIdService>(); | ||
|
||
services.AddSingleton<IConsoleReporter, ConsoleReporter>(); | ||
services.AddScoped<ISendGridReporter, SendGridReporter>(); | ||
services.AddScoped<INativeReporter, NativeReporter>(); | ||
services.AddScoped<IPostReporter, PostReporter>(); | ||
services.AddScoped<IReportService, ReportService>(); | ||
|
||
services.AddScoped<IFlaggedUserRule, FlaggedUserRule>(); | ||
services.AddScoped<IFlaggedInstanceRule, FlaggedInstanceRule>(); | ||
services.AddScoped<IFlaggedNoteRule, FlaggedNoteRule>(); | ||
services.AddScoped<IRuleService, RuleService>(); | ||
|
||
services.AddSingleton<ILinkService, LinkService>(); | ||
services.AddScoped<IMetaService, MetaService>(); | ||
services.AddScoped<IServiceAccountService, ServiceAccountService>(); | ||
services.AddHostedService<Worker>(); | ||
|
||
return services; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters