mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
cleanup some DI registration
This commit is contained in:
parent
ece0774045
commit
933091e76c
5 changed files with 9 additions and 29 deletions
|
|
@ -16,7 +16,7 @@ public static void AddApplicationInsights(this IServiceCollection services,
|
|||
return new QuickPulseTelemetryModuleBuilder(telemetryConfiguration).Build();
|
||||
});
|
||||
|
||||
// init never resolved singleton in intermediate ServiceProvider
|
||||
// init never resolved singleton
|
||||
services.BuildServiceProvider().GetService<QuickPulseTelemetryModule>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@ public static class ServiceCollectionExtensions
|
|||
public static void ConfigureServices(this IServiceCollection services)
|
||||
{
|
||||
services.ConfigureSettings();
|
||||
services.AddApplicationInsights(ApplicationInsightsSettings);
|
||||
services.AddLogging();
|
||||
services.AddApplicationInsights(ApplicationInsightsSettings);
|
||||
services.AddLocalization();
|
||||
services.AddTransient<Parser>();
|
||||
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
|
||||
services.AddPollyPolicyRegistry();
|
||||
services.AddDiskServices();
|
||||
services.AddDiskServices(Configuration.GetSettings<ArchiveSettings>());
|
||||
services.AddFilterListsApiServices();
|
||||
services.AddGitHubServices();
|
||||
services.AddGitHubServices(Configuration.GetSettings<GitHubSettings>());
|
||||
services.AddWebServices();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,15 @@
|
|||
using FilterLists.Agent.AppSettings;
|
||||
using LibGit2Sharp;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Disk
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static void AddDiskServices(this IServiceCollection services)
|
||||
public static void AddDiskServices(this IServiceCollection services, ArchiveSettings archiveSettings)
|
||||
{
|
||||
services.AddTransient<IRepository, Repository>(s =>
|
||||
{
|
||||
var archiveSettings = s.GetService<IOptions<ArchiveSettings>>().Value;
|
||||
if (!Repository.IsValid(archiveSettings.RepositoryDirectory))
|
||||
Repository.Init(archiveSettings.RepositoryDirectory);
|
||||
return new Repository(archiveSettings.RepositoryDirectory);
|
||||
|
|
|
|||
|
|
@ -1,23 +1,17 @@
|
|||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core.GitHub;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.GitHub
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static void AddGitHubServices(this IServiceCollection services)
|
||||
public static void AddGitHubServices(this IServiceCollection services, GitHubSettings gitHubSettings)
|
||||
{
|
||||
services.AddSingleton<IGitHubClient, GitHubClient>(s =>
|
||||
{
|
||||
var gitHubSettings = s.GetService<IOptions<GitHubSettings>>().Value;
|
||||
return new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubSettings.PersonalAccessToken)
|
||||
};
|
||||
});
|
||||
new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue))
|
||||
{Credentials = new Credentials(gitHubSettings.PersonalAccessToken)});
|
||||
services.AddTransient<IIssuesRepository, IssuesRepository>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@
|
|||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Polly;
|
||||
using Polly.Registry;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Polly
|
||||
{
|
||||
|
|
@ -20,17 +18,7 @@ public static void AddPollyPolicyRegistry(this IServiceCollection services)
|
|||
.WaitAndRetryAsync(3,
|
||||
(retryCount, response, context) =>
|
||||
response.Result?.Headers.RetryAfter.Delta ?? TimeSpan.FromMilliseconds(120),
|
||||
async (response, timespan, retryCount, context) =>
|
||||
{
|
||||
await Task.Run(() =>
|
||||
{
|
||||
var logger = services.BuildServiceProvider().GetService<ILogger<IPolicyRegistry<string>>>();
|
||||
logger.LogInformation("Retrying after 429 TooManyRequests",
|
||||
response.Result.RequestMessage.RequestUri,
|
||||
response.Result?.Headers.RetryAfter.Delta.ToString(),
|
||||
retryCount);
|
||||
});
|
||||
});
|
||||
async (response, timespan, retryCount, context) => { await Task.CompletedTask; });
|
||||
registry.Add(nameof(waitAndRetryTooManyRequests), waitAndRetryTooManyRequests);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue