mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
tidy DI registration
This commit is contained in:
parent
aef399ef2d
commit
6505d203c6
1 changed files with 24 additions and 16 deletions
|
|
@ -16,25 +16,11 @@ public static class ServiceCollectionExtensions
|
|||
public static void RegisterAgentServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddConfiguration();
|
||||
services.AddLogging(b =>
|
||||
{
|
||||
b.AddConsole();
|
||||
var appInsightsKey = b.Services.BuildServiceProvider().GetService<IOptions<ApplicationInsights>>().Value
|
||||
.InstrumentationKey;
|
||||
b.AddApplicationInsights(appInsightsKey);
|
||||
});
|
||||
services.AddLoggingCustom();
|
||||
services.AddMediatR(typeof(Program).Assembly);
|
||||
services.AddHttpClient<AgentHttpClient>();
|
||||
services.AddSingleton<IFilterListsApiClient, FilterListsApiClient>();
|
||||
services.AddSingleton<IGitHubClient>(s =>
|
||||
{
|
||||
var gitHubConfig = s.GetService<IOptions<GitHub>>();
|
||||
var client = new GitHubClient(new ProductHeaderValue(gitHubConfig.Value.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubConfig.Value.OauthToken)
|
||||
};
|
||||
return client;
|
||||
});
|
||||
services.AddGitHubClient();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IUrlRepository, UrlRepository>();
|
||||
}
|
||||
|
|
@ -52,5 +38,27 @@ private static void AddConfiguration(this IServiceCollection services)
|
|||
services.Configure<ConnectionStrings>(config.GetSection(nameof(ConnectionStrings)));
|
||||
services.Configure<GitHub>(config.GetSection(nameof(GitHub)));
|
||||
}
|
||||
|
||||
private static void AddLoggingCustom(this IServiceCollection services)
|
||||
{
|
||||
services.AddLogging(b =>
|
||||
{
|
||||
b.AddConsole();
|
||||
var appInsightsConfig = b.Services.BuildServiceProvider().GetService<IOptions<ApplicationInsights>>();
|
||||
b.AddApplicationInsights(appInsightsConfig.Value.InstrumentationKey);
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddGitHubClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IGitHubClient>(s =>
|
||||
{
|
||||
var gitHubConfig = s.GetService<IOptions<GitHub>>();
|
||||
return new GitHubClient(new ProductHeaderValue(gitHubConfig.Value.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubConfig.Value.OauthToken)
|
||||
};
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue