mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
re-org infrastructure/DI
This commit is contained in:
parent
cb3aa6776f
commit
b4d294a520
11 changed files with 71 additions and 53 deletions
|
|
@ -2,9 +2,9 @@
|
|||
using System.Threading.Tasks;
|
||||
using Octokit;
|
||||
|
||||
namespace FilterLists.Agent.Core
|
||||
namespace FilterLists.Agent.Core.GitHub
|
||||
{
|
||||
public interface IGitHubIssuesRepository
|
||||
public interface IIssuesRepository
|
||||
{
|
||||
Task<IReadOnlyList<Issue>> GetAllIssuesAsync(RepositoryIssueRequest repositoryIssueRequest);
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.GitHub;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using MediatR;
|
||||
using Octokit;
|
||||
|
|
@ -16,11 +16,11 @@ public class Command : IRequest
|
|||
public class Handler : AsyncRequestHandler<Command>
|
||||
{
|
||||
private const string AgentBotLabel = "agent bot";
|
||||
private readonly IGitHubIssuesRepository _repo;
|
||||
private readonly IIssuesRepository _repo;
|
||||
|
||||
public Handler(IGitHubIssuesRepository gitHubIssuesRepository)
|
||||
public Handler(IIssuesRepository issuesRepository)
|
||||
{
|
||||
_repo = gitHubIssuesRepository;
|
||||
_repo = issuesRepository;
|
||||
}
|
||||
|
||||
protected override async Task Handle(Command request, CancellationToken cancellationToken)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.GitHub;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using FilterLists.Agent.Features.Urls.Models.ValidationResults;
|
||||
using MediatR;
|
||||
|
|
@ -27,12 +27,12 @@ public class Handler : AsyncRequestHandler<Command>
|
|||
private const string HelpWantedLabel = "help wanted";
|
||||
private const string DataLabel = "data";
|
||||
private const string IssueTitle = "BOT: url validation errors";
|
||||
private readonly IGitHubIssuesRepository _repo;
|
||||
private readonly IMediator _mediator;
|
||||
private readonly IIssuesRepository _repo;
|
||||
|
||||
public Handler(IGitHubIssuesRepository gitHubIssuesRepository, IMediator mediator)
|
||||
public Handler(IIssuesRepository issuesRepository, IMediator mediator)
|
||||
{
|
||||
_repo = gitHubIssuesRepository;
|
||||
_repo = issuesRepository;
|
||||
_mediator = mediator;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,21 +4,17 @@
|
|||
using CommandLine;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using FilterLists.Agent.Infrastructure.Repositories;
|
||||
using FilterLists.Agent.Infrastructure.FilterListsApi;
|
||||
using FilterLists.Agent.Infrastructure.GitHub;
|
||||
using LibGit2Sharp;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
using Polly;
|
||||
using RestSharp;
|
||||
using Credentials = Octokit.Credentials;
|
||||
using Repository = LibGit2Sharp.Repository;
|
||||
|
||||
namespace FilterLists.Agent.Extensions
|
||||
namespace FilterLists.Agent.Infrastructure.DependencyInjection
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
|
|
@ -29,13 +25,11 @@ public static void RegisterAgentServices(this IServiceCollection services)
|
|||
services.AddLocalization();
|
||||
services.AddTransient<Parser>();
|
||||
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
|
||||
services.AddApiClient();
|
||||
services.AddGitHubClient();
|
||||
services.AddFilterListsApiResources();
|
||||
services.AddGitHubResources();
|
||||
services.AddUrlRepository();
|
||||
services.AddListRepository();
|
||||
services.AddArchiveRepository();
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
services.AddTransient<IGitHubIssuesRepository, GitHubIssuesRepository>();
|
||||
}
|
||||
|
||||
private static void AddConfiguration(this IServiceCollection services)
|
||||
|
|
@ -72,27 +66,6 @@ private static void AddLoggingCustom(this IServiceCollection services)
|
|||
});
|
||||
}
|
||||
|
||||
private static void AddApiClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IRestClient, RestClient>(b =>
|
||||
{
|
||||
var filterListsApiSettings = b.GetService<IOptions<FilterListsApiSettings>>().Value;
|
||||
return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"};
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddGitHubClient(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IGitHubClient, GitHubClient>(s =>
|
||||
{
|
||||
var gitHubSettings = s.GetService<IOptions<GitHubSettings>>().Value;
|
||||
return new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubSettings.PersonalAccessToken)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddUrlRepository(this IServiceCollection services)
|
||||
{
|
||||
services.AddHttpClient<IUrlRepository, UrlRepository>()
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
namespace FilterLists.Agent.Infrastructure.FilterListsApi
|
||||
{
|
||||
public class ListInfoRepository : IListInfoRepository
|
||||
{
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core.ListInfo;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.FilterListsApi
|
||||
{
|
||||
public static class ServiceCollectionExtensions
|
||||
{
|
||||
public static void AddFilterListsApiResources(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IRestClient, RestClient>(b =>
|
||||
{
|
||||
var filterListsApiSettings = b.GetService<IOptions<FilterListsApiSettings>>().Value;
|
||||
return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"};
|
||||
});
|
||||
services.AddTransient<IListInfoRepository, ListInfoRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +1,23 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using FilterLists.Agent.Core;
|
||||
using FilterLists.Agent.Core.GitHub;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
namespace FilterLists.Agent.Infrastructure.GitHub
|
||||
{
|
||||
public class GitHubIssuesRepository : IGitHubIssuesRepository
|
||||
public class IssuesRepository : IIssuesRepository
|
||||
{
|
||||
private readonly IGitHubClient _gitHubClient;
|
||||
private readonly GitHubSettings _gitHubSettings;
|
||||
private readonly IStringLocalizer<GitHubIssuesRepository> _localizer;
|
||||
private readonly ILogger<GitHubIssuesRepository> _logger;
|
||||
private readonly IStringLocalizer<IssuesRepository> _localizer;
|
||||
private readonly ILogger<IssuesRepository> _logger;
|
||||
|
||||
public GitHubIssuesRepository(IGitHubClient gitHubClient, IOptions<GitHubSettings> gitHubOptions,
|
||||
IStringLocalizer<GitHubIssuesRepository> stringLocalizer, ILogger<GitHubIssuesRepository> logger)
|
||||
public IssuesRepository(IGitHubClient gitHubClient, IOptions<GitHubSettings> gitHubOptions,
|
||||
IStringLocalizer<IssuesRepository> stringLocalizer, ILogger<IssuesRepository> logger)
|
||||
{
|
||||
_gitHubClient = gitHubClient;
|
||||
_gitHubSettings = gitHubOptions.Value;
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
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 AddGitHubResources(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<IGitHubClient, GitHubClient>(s =>
|
||||
{
|
||||
var gitHubSettings = s.GetService<IOptions<GitHubSettings>>().Value;
|
||||
return new GitHubClient(new ProductHeaderValue(gitHubSettings.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(gitHubSettings.PersonalAccessToken)
|
||||
};
|
||||
});
|
||||
services.AddTransient<IIssuesRepository, IssuesRepository>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
using FilterLists.Agent.Core;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
namespace FilterLists.Agent.Infrastructure
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class ListRepository : IListRepository
|
||||
|
|
@ -15,7 +15,7 @@
|
|||
using Microsoft.Extensions.Logging;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
namespace FilterLists.Agent.Infrastructure
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public class UrlRepository : IUrlRepository
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CommandLine;
|
||||
using FilterLists.Agent.Extensions;
|
||||
using FilterLists.Agent.Features.Lists;
|
||||
using FilterLists.Agent.Features.Urls;
|
||||
using FilterLists.Agent.Infrastructure.DependencyInjection;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue