From c88a7aee5e13d5cde784bb3b15db64512c796190 Mon Sep 17 00:00:00 2001 From: Sergey Nazarov Date: Sat, 30 Mar 2024 09:14:06 +0300 Subject: [PATCH] Update project structure --- Nocr.TextMatcher.sln | 6 ---- .../Nocr.TextMatcher.AppServices.csproj | 1 - .../ServiceCollectionExtensions.cs | 6 ++-- .../MessageReceivedHandler.cs | 6 ++-- .../ITextSubscriptionRepository.cs | 2 +- .../Services/ITextSubscriptionsService.cs | 2 +- .../Services/TextSubscriptionsService.cs | 4 +-- .../TextSubscriptions/TextSubscription.cs | 2 +- ...ocr.TextMatcher.Async.Api.Contracts.csproj | 4 +++ .../TextSubscriptionMatched.cs | 4 ++- .../Nocr.TextMatcher.Domain.csproj | 12 ------- .../TextSubscriptionsController.cs | 2 +- .../Infrastructure/Startup.cs | 11 +------ .../Nocr.TextMatcher.Persistence.csproj | 2 +- .../ServiceCollectionExtensions.cs | 32 +++++++++++++++++++ .../TextMatcherContext.cs | 3 +- .../TextSubscriptionConfiguration.cs | 4 +-- .../TextSubscriptionRepository.cs | 5 +-- .../TextSubscriptionTests.cs | 2 +- 19 files changed, 60 insertions(+), 50 deletions(-) rename src/Nocr.TextMatcher.AppServices/TextSubscriptions/{ => EventHandlers}/MessageReceivedHandler.cs (92%) rename src/Nocr.TextMatcher.AppServices/{TextMatches => TextSubscriptions}/Repositories/ITextSubscriptionRepository.cs (90%) rename src/Nocr.TextMatcher.AppServices/{TextMatches => TextSubscriptions}/Services/ITextSubscriptionsService.cs (92%) rename src/Nocr.TextMatcher.AppServices/{TextMatches => TextSubscriptions}/Services/TextSubscriptionsService.cs (96%) rename src/{Nocr.TextMatcher.Domain => Nocr.TextMatcher.AppServices}/TextSubscriptions/TextSubscription.cs (98%) delete mode 100644 src/Nocr.TextMatcher.Domain/Nocr.TextMatcher.Domain.csproj create mode 100644 src/Nocr.TextMatcher.Persistence/ServiceCollectionExtensions.cs rename src/Nocr.TextMatcher.Persistence/{ => TextSubscriptions}/TextSubscriptionConfiguration.cs (80%) rename src/{Nocr.TextMatcher.AppServices/TextMatches/Repositories => Nocr.TextMatcher.Persistence/TextSubscriptions}/TextSubscriptionRepository.cs (90%) diff --git a/Nocr.TextMatcher.sln b/Nocr.TextMatcher.sln index 1e5c82a..d698a8a 100644 --- a/Nocr.TextMatcher.sln +++ b/Nocr.TextMatcher.sln @@ -28,8 +28,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nocr.TextMatcher.Persistenc EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Contracts", "Contracts", "{0B8E28B3-EECC-4981-A87F-6D74C4F23371}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nocr.TextMatcher.Domain", "src\Nocr.TextMatcher.Domain\Nocr.TextMatcher.Domain.csproj", "{301BBDEA-ACF8-404D-83FA-AA26A8153D35}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -68,10 +66,6 @@ Global {D578EE54-B55A-4B45-859D-7F343C73EEF5}.Debug|Any CPU.Build.0 = Debug|Any CPU {D578EE54-B55A-4B45-859D-7F343C73EEF5}.Release|Any CPU.ActiveCfg = Release|Any CPU {D578EE54-B55A-4B45-859D-7F343C73EEF5}.Release|Any CPU.Build.0 = Release|Any CPU - {301BBDEA-ACF8-404D-83FA-AA26A8153D35}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {301BBDEA-ACF8-404D-83FA-AA26A8153D35}.Debug|Any CPU.Build.0 = Debug|Any CPU - {301BBDEA-ACF8-404D-83FA-AA26A8153D35}.Release|Any CPU.ActiveCfg = Release|Any CPU - {301BBDEA-ACF8-404D-83FA-AA26A8153D35}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {B721E055-84AF-44C6-973D-33241FD2EA7C} = {6E4D9F75-861F-4C00-A5C8-00D1BEE5A659} diff --git a/src/Nocr.TextMatcher.AppServices/Nocr.TextMatcher.AppServices.csproj b/src/Nocr.TextMatcher.AppServices/Nocr.TextMatcher.AppServices.csproj index 0145c78..1ffc738 100644 --- a/src/Nocr.TextMatcher.AppServices/Nocr.TextMatcher.AppServices.csproj +++ b/src/Nocr.TextMatcher.AppServices/Nocr.TextMatcher.AppServices.csproj @@ -15,7 +15,6 @@ - diff --git a/src/Nocr.TextMatcher.AppServices/ServiceCollectionExtensions.cs b/src/Nocr.TextMatcher.AppServices/ServiceCollectionExtensions.cs index a555b2a..e62de2f 100644 --- a/src/Nocr.TextMatcher.AppServices/ServiceCollectionExtensions.cs +++ b/src/Nocr.TextMatcher.AppServices/ServiceCollectionExtensions.cs @@ -1,7 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -using Nocr.TextMatcher.AppServices.TextMatches.Repositories; -using Nocr.TextMatcher.AppServices.TextMatches.Services; -using Nocr.TextMatcher.AppServices.TextSubscriptions; +using Nocr.TextMatcher.AppServices.TextSubscriptions.EventHandlers; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Services; using Rebus.Config; namespace Nocr.TextMatcher.AppServices; @@ -16,7 +15,6 @@ public static class ServiceCollectionExtensions // Add registrations here services.AddRebusHandler(); services.AddScoped(); - services.AddScoped(); return services; } diff --git a/src/Nocr.TextMatcher.AppServices/TextSubscriptions/MessageReceivedHandler.cs b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/EventHandlers/MessageReceivedHandler.cs similarity index 92% rename from src/Nocr.TextMatcher.AppServices/TextSubscriptions/MessageReceivedHandler.cs rename to src/Nocr.TextMatcher.AppServices/TextSubscriptions/EventHandlers/MessageReceivedHandler.cs index 31cd827..4e43982 100644 --- a/src/Nocr.TextMatcher.AppServices/TextSubscriptions/MessageReceivedHandler.cs +++ b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/EventHandlers/MessageReceivedHandler.cs @@ -1,12 +1,12 @@ using Microsoft.Extensions.Logging; using Nocr.TelegramListener.Async.Api.Contracts.Events; -using Nocr.TextMatcher.AppServices.TextMatches.Repositories; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; using Nocr.TextMatcher.Async.Api.Contracts; using Nocr.TextMatcher.Core.Dates; using Rebus.Bus; using Rebus.Handlers; -namespace Nocr.TextMatcher.AppServices.TextSubscriptions; +namespace Nocr.TextMatcher.AppServices.TextSubscriptions.EventHandlers; public sealed class MessageReceivedHandler : IHandleMessages { @@ -42,7 +42,7 @@ public sealed class MessageReceivedHandler : IHandleMessages SubscriptionId = match.Id, SubscriptionUserId = match.UserId, ChatUsername = match.ChatUsername, - Rule = (int)match.Rule, + Rule = match.Rule, Template = match.Template, Text = message.Text, From = message.From, diff --git a/src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/ITextSubscriptionRepository.cs b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Repositories/ITextSubscriptionRepository.cs similarity index 90% rename from src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/ITextSubscriptionRepository.cs rename to src/Nocr.TextMatcher.AppServices/TextSubscriptions/Repositories/ITextSubscriptionRepository.cs index 876238a..cb74135 100644 --- a/src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/ITextSubscriptionRepository.cs +++ b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Repositories/ITextSubscriptionRepository.cs @@ -1,4 +1,4 @@ -namespace Nocr.TextMatcher.AppServices.TextMatches.Repositories; +namespace Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; public interface ITextSubscriptionRepository { diff --git a/src/Nocr.TextMatcher.AppServices/TextMatches/Services/ITextSubscriptionsService.cs b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/ITextSubscriptionsService.cs similarity index 92% rename from src/Nocr.TextMatcher.AppServices/TextMatches/Services/ITextSubscriptionsService.cs rename to src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/ITextSubscriptionsService.cs index 4eb256e..237d32b 100644 --- a/src/Nocr.TextMatcher.AppServices/TextMatches/Services/ITextSubscriptionsService.cs +++ b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/ITextSubscriptionsService.cs @@ -1,7 +1,7 @@ using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto; using Nocr.TextMatcher.Contracts; -namespace Nocr.TextMatcher.AppServices.TextMatches.Services; +namespace Nocr.TextMatcher.AppServices.TextSubscriptions.Services; public interface ITextSubscriptionsService { diff --git a/src/Nocr.TextMatcher.AppServices/TextMatches/Services/TextSubscriptionsService.cs b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/TextSubscriptionsService.cs similarity index 96% rename from src/Nocr.TextMatcher.AppServices/TextMatches/Services/TextSubscriptionsService.cs rename to src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/TextSubscriptionsService.cs index 8fba6a9..b58ae04 100644 --- a/src/Nocr.TextMatcher.AppServices/TextMatches/Services/TextSubscriptionsService.cs +++ b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/Services/TextSubscriptionsService.cs @@ -1,11 +1,11 @@ using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto; -using Nocr.TextMatcher.AppServices.TextMatches.Repositories; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; using Nocr.TextMatcher.Async.Api.Contracts; using Nocr.TextMatcher.Contracts; using Nocr.TextMatcher.Core.Dates; using Rebus.Bus; -namespace Nocr.TextMatcher.AppServices.TextMatches.Services; +namespace Nocr.TextMatcher.AppServices.TextSubscriptions.Services; public sealed class TextSubscriptionsService : ITextSubscriptionsService { diff --git a/src/Nocr.TextMatcher.Domain/TextSubscriptions/TextSubscription.cs b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/TextSubscription.cs similarity index 98% rename from src/Nocr.TextMatcher.Domain/TextSubscriptions/TextSubscription.cs rename to src/Nocr.TextMatcher.AppServices/TextSubscriptions/TextSubscription.cs index c0a0ae6..b6f0a2a 100644 --- a/src/Nocr.TextMatcher.Domain/TextSubscriptions/TextSubscription.cs +++ b/src/Nocr.TextMatcher.AppServices/TextSubscriptions/TextSubscription.cs @@ -1,7 +1,7 @@ using System.Text.RegularExpressions; using Nocr.TextMatcher.Contracts; -namespace Nocr.TextMatcher.AppServices.TextMatches; +namespace Nocr.TextMatcher.AppServices.TextSubscriptions; public sealed class TextSubscription { diff --git a/src/Nocr.TextMatcher.Async.Api.Contracts/Nocr.TextMatcher.Async.Api.Contracts.csproj b/src/Nocr.TextMatcher.Async.Api.Contracts/Nocr.TextMatcher.Async.Api.Contracts.csproj index ae01cf7..a897c95 100644 --- a/src/Nocr.TextMatcher.Async.Api.Contracts/Nocr.TextMatcher.Async.Api.Contracts.csproj +++ b/src/Nocr.TextMatcher.Async.Api.Contracts/Nocr.TextMatcher.Async.Api.Contracts.csproj @@ -4,4 +4,8 @@ true + + + + diff --git a/src/Nocr.TextMatcher.Async.Api.Contracts/TextSubscriptionMatched.cs b/src/Nocr.TextMatcher.Async.Api.Contracts/TextSubscriptionMatched.cs index e921fc3..7fcfbfc 100644 --- a/src/Nocr.TextMatcher.Async.Api.Contracts/TextSubscriptionMatched.cs +++ b/src/Nocr.TextMatcher.Async.Api.Contracts/TextSubscriptionMatched.cs @@ -1,3 +1,5 @@ +using Nocr.TextMatcher.Contracts; + namespace Nocr.TextMatcher.Async.Api.Contracts; public class TextSubscriptionMatched : IEvent @@ -22,7 +24,7 @@ public class TextSubscriptionMatched : IEvent /// /// Правило совпадения /// - public int Rule { get; set; } + public TextSubscriptionRule Rule { get; set; } /// /// Шаблон совпадения diff --git a/src/Nocr.TextMatcher.Domain/Nocr.TextMatcher.Domain.csproj b/src/Nocr.TextMatcher.Domain/Nocr.TextMatcher.Domain.csproj deleted file mode 100644 index 2c71e7c..0000000 --- a/src/Nocr.TextMatcher.Domain/Nocr.TextMatcher.Domain.csproj +++ /dev/null @@ -1,12 +0,0 @@ - - - - - false - - - - - - - diff --git a/src/Nocr.TextMatcher.Host/Controllers/TextSubscriptionsController.cs b/src/Nocr.TextMatcher.Host/Controllers/TextSubscriptionsController.cs index 4257dab..9ec48d5 100644 --- a/src/Nocr.TextMatcher.Host/Controllers/TextSubscriptionsController.cs +++ b/src/Nocr.TextMatcher.Host/Controllers/TextSubscriptionsController.cs @@ -2,7 +2,7 @@ using Microsoft.AspNetCore.Mvc; using Nocr.TextMatcher.Api.Contracts; using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto; using Nocr.TextMatcher.Api.Contracts.TextMatches.Requests; -using Nocr.TextMatcher.AppServices.TextMatches.Services; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Services; namespace Nocr.TextMatcher.Host.Controllers; diff --git a/src/Nocr.TextMatcher.Host/Infrastructure/Startup.cs b/src/Nocr.TextMatcher.Host/Infrastructure/Startup.cs index 38cc9cb..9394bc8 100644 --- a/src/Nocr.TextMatcher.Host/Infrastructure/Startup.cs +++ b/src/Nocr.TextMatcher.Host/Infrastructure/Startup.cs @@ -1,4 +1,3 @@ -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Options; using Nocr.TextMatcher.AppServices; using Nocr.TextMatcher.Core.Dates; @@ -30,15 +29,7 @@ public class Startup services.AddSwaggerGen(); services.AddAppServices(); - services.AddDbContext( - (ctx, context) => - { - context.UseMySql(Configuration.GetConnectionString(nameof(TextMatcherContext)), - new MariaDbServerVersion(MariaDbServerVersion.LatestSupportedServerVersion), - builder => builder.MigrationsAssembly(typeof(TextMatcherContext).Assembly.FullName)) - .UseLoggerFactory(ctx.GetRequiredService()); - } - ); + services.AddEfPersistence(Configuration.GetConnectionString(nameof(TextMatcherContext))!); services.Configure(Configuration.GetSection(nameof(RebusRabbitMqOptions))); services.AddRebus((builder, ctx) => diff --git a/src/Nocr.TextMatcher.Persistence/Nocr.TextMatcher.Persistence.csproj b/src/Nocr.TextMatcher.Persistence/Nocr.TextMatcher.Persistence.csproj index 4ccab86..d45cacd 100644 --- a/src/Nocr.TextMatcher.Persistence/Nocr.TextMatcher.Persistence.csproj +++ b/src/Nocr.TextMatcher.Persistence/Nocr.TextMatcher.Persistence.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/Nocr.TextMatcher.Persistence/ServiceCollectionExtensions.cs b/src/Nocr.TextMatcher.Persistence/ServiceCollectionExtensions.cs new file mode 100644 index 0000000..dd63d31 --- /dev/null +++ b/src/Nocr.TextMatcher.Persistence/ServiceCollectionExtensions.cs @@ -0,0 +1,32 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; +using Nocr.TextMatcher.Persistence.TextSubscriptions; + +namespace Nocr.TextMatcher.Persistence; + +public static class ServiceCollectionExtensions +{ + public static IServiceCollection AddEfPersistence(this IServiceCollection services, string connectionString) + { + if (services == null) + throw new ArgumentNullException(nameof(services)); + + if (string.IsNullOrWhiteSpace(connectionString)) + throw new ArgumentNullException(nameof(connectionString)); + + services.AddScoped(); + + services.AddDbContext( + (ctx, context) => + { + context.UseMySql(connectionString, new MariaDbServerVersion(MariaDbServerVersion.LatestSupportedServerVersion), + builder => builder.MigrationsAssembly(typeof(TextMatcherContext).Assembly.FullName)) + .UseLoggerFactory(ctx.GetRequiredService()); + } + ); + + return services; + } +} \ No newline at end of file diff --git a/src/Nocr.TextMatcher.Persistence/TextMatcherContext.cs b/src/Nocr.TextMatcher.Persistence/TextMatcherContext.cs index 150e604..3640cb1 100644 --- a/src/Nocr.TextMatcher.Persistence/TextMatcherContext.cs +++ b/src/Nocr.TextMatcher.Persistence/TextMatcherContext.cs @@ -1,5 +1,6 @@ using Microsoft.EntityFrameworkCore; -using Nocr.TextMatcher.AppServices.TextMatches; +using Nocr.TextMatcher.AppServices.TextSubscriptions; +using Nocr.TextMatcher.Persistence.TextSubscriptions; namespace Nocr.TextMatcher.Persistence; diff --git a/src/Nocr.TextMatcher.Persistence/TextSubscriptionConfiguration.cs b/src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionConfiguration.cs similarity index 80% rename from src/Nocr.TextMatcher.Persistence/TextSubscriptionConfiguration.cs rename to src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionConfiguration.cs index 6de47ec..d649f08 100644 --- a/src/Nocr.TextMatcher.Persistence/TextSubscriptionConfiguration.cs +++ b/src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionConfiguration.cs @@ -1,8 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using Nocr.TextMatcher.AppServices.TextMatches; +using Nocr.TextMatcher.AppServices.TextSubscriptions; -namespace Nocr.TextMatcher.Persistence; +namespace Nocr.TextMatcher.Persistence.TextSubscriptions; public class TextSubscriptionConfiguration : IEntityTypeConfiguration { diff --git a/src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/TextSubscriptionRepository.cs b/src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionRepository.cs similarity index 90% rename from src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/TextSubscriptionRepository.cs rename to src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionRepository.cs index a70f85b..7d7f0fd 100644 --- a/src/Nocr.TextMatcher.AppServices/TextMatches/Repositories/TextSubscriptionRepository.cs +++ b/src/Nocr.TextMatcher.Persistence/TextSubscriptions/TextSubscriptionRepository.cs @@ -1,7 +1,8 @@ using Microsoft.EntityFrameworkCore; -using Nocr.TextMatcher.Persistence; +using Nocr.TextMatcher.AppServices.TextSubscriptions; +using Nocr.TextMatcher.AppServices.TextSubscriptions.Repositories; -namespace Nocr.TextMatcher.AppServices.TextMatches.Repositories; +namespace Nocr.TextMatcher.Persistence.TextSubscriptions; public sealed class TextSubscriptionRepository : ITextSubscriptionRepository { diff --git a/tests/Nocr.TextMatcher.AppServices.UnitTests/TextSubscriptionTests.cs b/tests/Nocr.TextMatcher.AppServices.UnitTests/TextSubscriptionTests.cs index 11b0d74..0fecc08 100644 --- a/tests/Nocr.TextMatcher.AppServices.UnitTests/TextSubscriptionTests.cs +++ b/tests/Nocr.TextMatcher.AppServices.UnitTests/TextSubscriptionTests.cs @@ -1,4 +1,4 @@ -using Nocr.TextMatcher.AppServices.TextMatches; +using Nocr.TextMatcher.AppServices.TextSubscriptions; using Nocr.TextMatcher.Contracts; using Xunit;