diff --git a/.github/workflows/account-management.yml b/.github/workflows/platformplatform.yml similarity index 80% rename from .github/workflows/account-management.yml rename to .github/workflows/platformplatform.yml index 12a5fe8f3..9fbeade1f 100644 --- a/.github/workflows/account-management.yml +++ b/.github/workflows/platformplatform.yml @@ -1,4 +1,4 @@ -name: "Account Management" +name: "PlatformPlatform" on: push: @@ -23,11 +23,9 @@ jobs: echo "Generated version: $VERSION" echo "VERSION=$VERSION" >> $GITHUB_ENV - name: Restore dependencies - working-directory: account-management - run: dotnet restore AccountManagement.sln + run: dotnet restore PlatformPlatform.sln - name: Build - working-directory: account-management - run: dotnet build AccountManagement.sln --no-restore --configuration Release /p:Version=$VERSION + run: dotnet build PlatformPlatform.sln --no-restore --configuration Release /p:Version=$VERSION test-with-code-coverage: needs: build @@ -47,13 +45,12 @@ jobs: - name: Install SonarScanner run: dotnet tool install --global dotnet-sonarscanner - name: Run Test with dotCover and SonarScanner reporting - working-directory: account-management env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} run: | dotnet sonarscanner begin /k:"${{ vars.SONAR_PROJECT_KEY }}" /o:"${{ vars.SONAR_ORGANIZATION }}" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.dotcover.reportsPaths="coverage/dotCover.html" - dotnet dotcover test AccountManagement.sln --dcOutput="coverage/dotCover.html" --dcReportType=HTML + dotnet dotcover test PlatformPlatform.sln --dcOutput="coverage/dotCover.html" --dcReportType=HTML dotnet sonarscanner end /d:sonar.login="${SONAR_TOKEN}" jetbrains-code-inspection: @@ -66,7 +63,7 @@ jobs: - name: Run code inspections uses: muno92/resharper_inspectcode@1.6.13 with: - solutionPath: account-management/AccountManagement.sln + solutionPath: PlatformPlatform.sln minimumSeverity: warning # Ignore cases where property getters are not called directly (e.g., on DTOs that are serialized) ignoreIssueType: UnusedAutoPropertyAccessor.Global diff --git a/.gitignore b/.gitignore index af97a2fee..cabc98514 100644 --- a/.gitignore +++ b/.gitignore @@ -135,7 +135,7 @@ _ReSharper*/ *.DotSettings.user # Rider -*/.idea +.idea # TeamCity is a build add-in _TeamCity* diff --git a/PlatformPlatform.sln b/PlatformPlatform.sln new file mode 100644 index 000000000..5991a1e23 --- /dev/null +++ b/PlatformPlatform.sln @@ -0,0 +1,79 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "backend-foundation", "backend-foundation", "{F01E4DC8-2A8B-4CB9-893A-B3B8FF2EFE22}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DomainModeling", "backend-foundation\DomainModeling\DomainModeling.csproj", "{9781DA05-517E-46D7-9F8B-2C01AA74F1E4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfrastructureCore", "backend-foundation\InfrastructureCore\InfrastructureCore.csproj", "{2B5B1AC7-7254-4527-B0F0-8F0A203CB625}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreUtils", "backend-foundation\AspNetCoreUtils\AspNetCoreUtils.csproj", "{836ABCEF-C16B-4331-B8D5-0EA75E4101FE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "backend-foundation\Tests\Tests.csproj", "{B232D7BB-396A-46FE-B6D2-95041412C835}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "account-management", "account-management", "{EEA1463E-71F8-44E6-8055-787DAA5E62D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "account-management\Domain\Domain.csproj", "{32C5BCAB-FC18-4C32-B008-E0FD125C5E98}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "account-management\Application\Application.csproj", "{B155D1D9-4F6E-42AE-A8F0-92CD50BF182D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "account-management\Infrastructure\Infrastructure.csproj", "{CB9BAD74-4362-4646-B653-3CB5FCAC74BD}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "account-management\WebApi\WebApi.csproj", "{4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "account-management\Tests\Tests.csproj", "{ABEB4337-3606-4730-8ABE-94DF98C2C348}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {9781DA05-517E-46D7-9F8B-2C01AA74F1E4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9781DA05-517E-46D7-9F8B-2C01AA74F1E4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9781DA05-517E-46D7-9F8B-2C01AA74F1E4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9781DA05-517E-46D7-9F8B-2C01AA74F1E4}.Release|Any CPU.Build.0 = Release|Any CPU + {2B5B1AC7-7254-4527-B0F0-8F0A203CB625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2B5B1AC7-7254-4527-B0F0-8F0A203CB625}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2B5B1AC7-7254-4527-B0F0-8F0A203CB625}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2B5B1AC7-7254-4527-B0F0-8F0A203CB625}.Release|Any CPU.Build.0 = Release|Any CPU + {836ABCEF-C16B-4331-B8D5-0EA75E4101FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {836ABCEF-C16B-4331-B8D5-0EA75E4101FE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {836ABCEF-C16B-4331-B8D5-0EA75E4101FE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {836ABCEF-C16B-4331-B8D5-0EA75E4101FE}.Release|Any CPU.Build.0 = Release|Any CPU + {B232D7BB-396A-46FE-B6D2-95041412C835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B232D7BB-396A-46FE-B6D2-95041412C835}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B232D7BB-396A-46FE-B6D2-95041412C835}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B232D7BB-396A-46FE-B6D2-95041412C835}.Release|Any CPU.Build.0 = Release|Any CPU + {32C5BCAB-FC18-4C32-B008-E0FD125C5E98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32C5BCAB-FC18-4C32-B008-E0FD125C5E98}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32C5BCAB-FC18-4C32-B008-E0FD125C5E98}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32C5BCAB-FC18-4C32-B008-E0FD125C5E98}.Release|Any CPU.Build.0 = Release|Any CPU + {B155D1D9-4F6E-42AE-A8F0-92CD50BF182D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B155D1D9-4F6E-42AE-A8F0-92CD50BF182D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B155D1D9-4F6E-42AE-A8F0-92CD50BF182D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B155D1D9-4F6E-42AE-A8F0-92CD50BF182D}.Release|Any CPU.Build.0 = Release|Any CPU + {CB9BAD74-4362-4646-B653-3CB5FCAC74BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CB9BAD74-4362-4646-B653-3CB5FCAC74BD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CB9BAD74-4362-4646-B653-3CB5FCAC74BD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CB9BAD74-4362-4646-B653-3CB5FCAC74BD}.Release|Any CPU.Build.0 = Release|Any CPU + {4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE}.Release|Any CPU.Build.0 = Release|Any CPU + {ABEB4337-3606-4730-8ABE-94DF98C2C348}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {ABEB4337-3606-4730-8ABE-94DF98C2C348}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ABEB4337-3606-4730-8ABE-94DF98C2C348}.Release|Any CPU.ActiveCfg = Release|Any CPU + {ABEB4337-3606-4730-8ABE-94DF98C2C348}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {9781DA05-517E-46D7-9F8B-2C01AA74F1E4} = {F01E4DC8-2A8B-4CB9-893A-B3B8FF2EFE22} + {2B5B1AC7-7254-4527-B0F0-8F0A203CB625} = {F01E4DC8-2A8B-4CB9-893A-B3B8FF2EFE22} + {836ABCEF-C16B-4331-B8D5-0EA75E4101FE} = {F01E4DC8-2A8B-4CB9-893A-B3B8FF2EFE22} + {B232D7BB-396A-46FE-B6D2-95041412C835} = {F01E4DC8-2A8B-4CB9-893A-B3B8FF2EFE22} + {32C5BCAB-FC18-4C32-B008-E0FD125C5E98} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} + {B155D1D9-4F6E-42AE-A8F0-92CD50BF182D} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} + {CB9BAD74-4362-4646-B653-3CB5FCAC74BD} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} + {4AF4767C-1BF5-4B86-9050-F05ABF6AF4BE} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} + {ABEB4337-3606-4730-8ABE-94DF98C2C348} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} + EndGlobalSection +EndGlobal diff --git a/account-management/AccountManagement.sln b/account-management/AccountManagement.sln deleted file mode 100644 index 81cb6a192..000000000 --- a/account-management/AccountManagement.sln +++ /dev/null @@ -1,65 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{EEA1463E-71F8-44E6-8055-787DAA5E62D2}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundation", "src\Foundation\Foundation.csproj", "{92CECDBD-ADDD-437B-A848-9A663BA56213}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Domain", "src\Domain\Domain.csproj", "{254BF290-0F52-40FD-9776-25660C34D8CE}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "src\Application\Application.csproj", "{51EA2C15-ACB4-40FF-A6F2-05512BED7264}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Infrastructure", "src\Infrastructure\Infrastructure.csproj", "{E4D8E1A7-0712-4233-A231-6F7AFB7AD626}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebApi", "src\WebApi\WebApi.csproj", "{1742F903-4158-4924-9F9C-3B3BE7E99C67}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0E389279-C3EB-4F9F-8068-8A12F0D526F2}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Foundation.Tests", "tests\Foundation.Tests\Foundation.Tests.csproj", "{B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "tests\Tests\Tests.csproj", "{FACCD4EB-C878-45DA-8CD8-5CCFA2A59205}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {92CECDBD-ADDD-437B-A848-9A663BA56213}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {92CECDBD-ADDD-437B-A848-9A663BA56213}.Debug|Any CPU.Build.0 = Debug|Any CPU - {92CECDBD-ADDD-437B-A848-9A663BA56213}.Release|Any CPU.ActiveCfg = Release|Any CPU - {92CECDBD-ADDD-437B-A848-9A663BA56213}.Release|Any CPU.Build.0 = Release|Any CPU - {254BF290-0F52-40FD-9776-25660C34D8CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {254BF290-0F52-40FD-9776-25660C34D8CE}.Debug|Any CPU.Build.0 = Debug|Any CPU - {254BF290-0F52-40FD-9776-25660C34D8CE}.Release|Any CPU.ActiveCfg = Release|Any CPU - {254BF290-0F52-40FD-9776-25660C34D8CE}.Release|Any CPU.Build.0 = Release|Any CPU - {51EA2C15-ACB4-40FF-A6F2-05512BED7264}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {51EA2C15-ACB4-40FF-A6F2-05512BED7264}.Debug|Any CPU.Build.0 = Debug|Any CPU - {51EA2C15-ACB4-40FF-A6F2-05512BED7264}.Release|Any CPU.ActiveCfg = Release|Any CPU - {51EA2C15-ACB4-40FF-A6F2-05512BED7264}.Release|Any CPU.Build.0 = Release|Any CPU - {E4D8E1A7-0712-4233-A231-6F7AFB7AD626}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {E4D8E1A7-0712-4233-A231-6F7AFB7AD626}.Debug|Any CPU.Build.0 = Debug|Any CPU - {E4D8E1A7-0712-4233-A231-6F7AFB7AD626}.Release|Any CPU.ActiveCfg = Release|Any CPU - {E4D8E1A7-0712-4233-A231-6F7AFB7AD626}.Release|Any CPU.Build.0 = Release|Any CPU - {1742F903-4158-4924-9F9C-3B3BE7E99C67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1742F903-4158-4924-9F9C-3B3BE7E99C67}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1742F903-4158-4924-9F9C-3B3BE7E99C67}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1742F903-4158-4924-9F9C-3B3BE7E99C67}.Release|Any CPU.Build.0 = Release|Any CPU - {FACCD4EB-C878-45DA-8CD8-5CCFA2A59205}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {FACCD4EB-C878-45DA-8CD8-5CCFA2A59205}.Debug|Any CPU.Build.0 = Debug|Any CPU - {FACCD4EB-C878-45DA-8CD8-5CCFA2A59205}.Release|Any CPU.ActiveCfg = Release|Any CPU - {FACCD4EB-C878-45DA-8CD8-5CCFA2A59205}.Release|Any CPU.Build.0 = Release|Any CPU - {B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(NestedProjects) = preSolution - {92CECDBD-ADDD-437B-A848-9A663BA56213} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} - {254BF290-0F52-40FD-9776-25660C34D8CE} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} - {51EA2C15-ACB4-40FF-A6F2-05512BED7264} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} - {E4D8E1A7-0712-4233-A231-6F7AFB7AD626} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} - {1742F903-4158-4924-9F9C-3B3BE7E99C67} = {EEA1463E-71F8-44E6-8055-787DAA5E62D2} - {FACCD4EB-C878-45DA-8CD8-5CCFA2A59205} = {0E389279-C3EB-4F9F-8068-8A12F0D526F2} - {B1E9935F-2A8C-41F1-BC72-BB5D062F9CB0} = {0E389279-C3EB-4F9F-8068-8A12F0D526F2} - EndGlobalSection -EndGlobal diff --git a/account-management/src/Application/Application.csproj b/account-management/Application/Application.csproj similarity index 100% rename from account-management/src/Application/Application.csproj rename to account-management/Application/Application.csproj diff --git a/account-management/src/Application/ApplicationConfiguration.cs b/account-management/Application/ApplicationConfiguration.cs similarity index 74% rename from account-management/src/Application/ApplicationConfiguration.cs rename to account-management/Application/ApplicationConfiguration.cs index 42c79f0a5..a40dfb08a 100644 --- a/account-management/src/Application/ApplicationConfiguration.cs +++ b/account-management/Application/ApplicationConfiguration.cs @@ -1,6 +1,7 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; using PlatformPlatform.AccountManagement.Application.Tenants.Dtos; +using PlatformPlatform.Foundation.DomainModeling; namespace PlatformPlatform.AccountManagement.Application; @@ -14,9 +15,10 @@ public static class ApplicationConfiguration public static IServiceCollection AddApplicationServices(this IServiceCollection services) { - services.AddMediatR(configuration => configuration.RegisterServicesFromAssemblies(Assembly)); - - ConfigureMappings(); + services + .AddDomainModelingServices() + .ConfigureMappings() + .AddMediatR(configuration => configuration.RegisterServicesFromAssemblies(Assembly)); return services; } @@ -26,8 +28,10 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection /// convention-based mapping, which means no configuration is needed if properties are named the same in both /// the DTO and the Entity. However, it can be configured to use explicit mappings. /// - private static void ConfigureMappings() + private static IServiceCollection ConfigureMappings(this IServiceCollection services) { TenantDto.ConfigureTenantDtoMapping(); + + return services; } } \ No newline at end of file diff --git a/account-management/src/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs b/account-management/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs similarity index 85% rename from account-management/src/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs rename to account-management/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs index 8415e8aa2..a572cd720 100644 --- a/account-management/src/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs +++ b/account-management/Application/Tenants/Commands/CreateTenant/CreateTenantCommand.cs @@ -3,8 +3,8 @@ using MediatR; using PlatformPlatform.AccountManagement.Application.Tenants.Dtos; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.Application; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; +using PlatformPlatform.Foundation.DomainModeling.Validation; namespace PlatformPlatform.AccountManagement.Application.Tenants.Commands.CreateTenant; @@ -48,11 +48,11 @@ public async Task> Handle(CreateTenantCommand command, return tenant.Adapt(); } - private async Task IsSubdomainUniqueAsync(string subdomain, CancellationToken cancellationToken) + private async Task IsSubdomainUniqueAsync(string subdomain, CancellationToken cancellationToken) { var isSubdomainUnique = await _tenantRepository.IsSubdomainFreeAsync(subdomain, cancellationToken); return isSubdomainUnique - ? Result.Success() - : Result.Failure(nameof(Tenant.Subdomain), "The subdomain must be unique."); + ? ValidationResult.Success() + : ValidationResult.Failure(nameof(Tenant.Subdomain), "The subdomain must be unique."); } } \ No newline at end of file diff --git a/account-management/src/Application/Tenants/Commands/CreateTenant/TenantCreatedEventHandler.cs b/account-management/Application/Tenants/Commands/CreateTenant/TenantCreatedEventHandler.cs similarity index 100% rename from account-management/src/Application/Tenants/Commands/CreateTenant/TenantCreatedEventHandler.cs rename to account-management/Application/Tenants/Commands/CreateTenant/TenantCreatedEventHandler.cs diff --git a/account-management/src/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs b/account-management/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs similarity index 90% rename from account-management/src/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs rename to account-management/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs index e4b410e01..2206ebe7f 100644 --- a/account-management/src/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs +++ b/account-management/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommand.cs @@ -2,8 +2,8 @@ using MediatR; using PlatformPlatform.AccountManagement.Application.Tenants.Dtos; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.Application; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; +using PlatformPlatform.Foundation.DomainModeling.Validation; namespace PlatformPlatform.AccountManagement.Application.Tenants.Commands.DeleteTenant; diff --git a/account-management/src/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs b/account-management/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs similarity index 93% rename from account-management/src/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs rename to account-management/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs index 55c2f4dc0..9b70bd2e6 100644 --- a/account-management/src/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs +++ b/account-management/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommand.cs @@ -3,8 +3,8 @@ using MediatR; using PlatformPlatform.AccountManagement.Application.Tenants.Dtos; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.Application; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; +using PlatformPlatform.Foundation.DomainModeling.Validation; namespace PlatformPlatform.AccountManagement.Application.Tenants.Commands.UpdateTenant; diff --git a/account-management/src/Application/Tenants/Dtos/TenantDto.cs b/account-management/Application/Tenants/Dtos/TenantDto.cs similarity index 100% rename from account-management/src/Application/Tenants/Dtos/TenantDto.cs rename to account-management/Application/Tenants/Dtos/TenantDto.cs diff --git a/account-management/src/Application/Tenants/Queries/GetTenantByIdQuery.cs b/account-management/Application/Tenants/Queries/GetTenantByIdQuery.cs similarity index 95% rename from account-management/src/Application/Tenants/Queries/GetTenantByIdQuery.cs rename to account-management/Application/Tenants/Queries/GetTenantByIdQuery.cs index 35cab8de0..5bacd8761 100644 --- a/account-management/src/Application/Tenants/Queries/GetTenantByIdQuery.cs +++ b/account-management/Application/Tenants/Queries/GetTenantByIdQuery.cs @@ -2,7 +2,7 @@ using MediatR; using PlatformPlatform.AccountManagement.Application.Tenants.Dtos; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.Application; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; namespace PlatformPlatform.AccountManagement.Application.Tenants.Queries; diff --git a/account-management/src/Domain/Domain.csproj b/account-management/Domain/Domain.csproj similarity index 84% rename from account-management/src/Domain/Domain.csproj rename to account-management/Domain/Domain.csproj index 0aaad4758..b2dcc8d1f 100644 --- a/account-management/src/Domain/Domain.csproj +++ b/account-management/Domain/Domain.csproj @@ -9,11 +9,11 @@ - + - + diff --git a/account-management/src/Domain/DomainConfiguration.cs b/account-management/Domain/DomainConfiguration.cs similarity index 100% rename from account-management/src/Domain/DomainConfiguration.cs rename to account-management/Domain/DomainConfiguration.cs diff --git a/account-management/src/Domain/Tenants/ITenantRepository.cs b/account-management/Domain/Tenants/ITenantRepository.cs similarity index 78% rename from account-management/src/Domain/Tenants/ITenantRepository.cs rename to account-management/Domain/Tenants/ITenantRepository.cs index 03b422519..25c80087b 100644 --- a/account-management/src/Domain/Tenants/ITenantRepository.cs +++ b/account-management/Domain/Tenants/ITenantRepository.cs @@ -1,4 +1,4 @@ -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Persistence; namespace PlatformPlatform.AccountManagement.Domain.Tenants; diff --git a/account-management/src/Domain/Tenants/Tenant.cs b/account-management/Domain/Tenants/Tenant.cs similarity index 93% rename from account-management/src/Domain/Tenants/Tenant.cs rename to account-management/Domain/Tenants/Tenant.cs index a30ae632f..9c233db80 100644 --- a/account-management/src/Domain/Tenants/Tenant.cs +++ b/account-management/Domain/Tenants/Tenant.cs @@ -1,4 +1,5 @@ -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Identity; namespace PlatformPlatform.AccountManagement.Domain.Tenants; diff --git a/account-management/src/Domain/Tenants/TenantCreatedEvent.cs b/account-management/Domain/Tenants/TenantCreatedEvent.cs similarity index 66% rename from account-management/src/Domain/Tenants/TenantCreatedEvent.cs rename to account-management/Domain/Tenants/TenantCreatedEvent.cs index 56cacce97..e81844ed4 100644 --- a/account-management/src/Domain/Tenants/TenantCreatedEvent.cs +++ b/account-management/Domain/Tenants/TenantCreatedEvent.cs @@ -1,5 +1,5 @@ using JetBrains.Annotations; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.DomainEvents; namespace PlatformPlatform.AccountManagement.Domain.Tenants; diff --git a/account-management/src/Domain/Tenants/TenantState.cs b/account-management/Domain/Tenants/TenantState.cs similarity index 100% rename from account-management/src/Domain/Tenants/TenantState.cs rename to account-management/Domain/Tenants/TenantState.cs diff --git a/account-management/src/Domain/Tenants/TenantValidation.cs b/account-management/Domain/Tenants/TenantValidation.cs similarity index 68% rename from account-management/src/Domain/Tenants/TenantValidation.cs rename to account-management/Domain/Tenants/TenantValidation.cs index e7e93acf8..18dfa4b4f 100644 --- a/account-management/src/Domain/Tenants/TenantValidation.cs +++ b/account-management/Domain/Tenants/TenantValidation.cs @@ -1,27 +1,27 @@ -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Validation; namespace PlatformPlatform.AccountManagement.Domain.Tenants; public static class TenantValidation { - public static Result ValidateName(string input) + public static ValidationResult ValidateName(string input) { const string errorMessage = "Name must be between 1 and 30 characters."; return ValidationUtils.IsStringValid(nameof(Tenant.Name), input, 1, 30, errorMessage); } - public static Result ValidateSubdomain(string input) + public static ValidationResult ValidateSubdomain(string input) { const string errorMessage = "Subdomains should be 3 to 30 lowercase alphanumeric characters."; return ValidationUtils.IsStringValid(nameof(Tenant.Subdomain), input, "^[a-z0-9]*$", 3, 30, errorMessage); } - public static Result ValidateEmail(string input) + public static ValidationResult ValidateEmail(string input) { return ValidationUtils.IsValidEmail(nameof(Tenant.Email), input); } - public static Result ValidatePhone(string? input) + public static ValidationResult ValidatePhone(string? input) { return ValidationUtils.IsValidPhone(nameof(Tenant.Phone), input); } diff --git a/account-management/src/Infrastructure/ApplicationDbContext.cs b/account-management/Infrastructure/ApplicationDbContext.cs similarity index 89% rename from account-management/src/Infrastructure/ApplicationDbContext.cs rename to account-management/Infrastructure/ApplicationDbContext.cs index 89f96f042..cb4511e12 100644 --- a/account-management/src/Infrastructure/ApplicationDbContext.cs +++ b/account-management/Infrastructure/ApplicationDbContext.cs @@ -1,8 +1,8 @@ using System.Diagnostics.CodeAnalysis; using Microsoft.EntityFrameworkCore; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.Domain; -using PlatformPlatform.Foundation.Infrastructure; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.InfrastructureCore.EntityFramework; namespace PlatformPlatform.AccountManagement.Infrastructure; diff --git a/account-management/src/Infrastructure/Infrastructure.csproj b/account-management/Infrastructure/Infrastructure.csproj similarity index 82% rename from account-management/src/Infrastructure/Infrastructure.csproj rename to account-management/Infrastructure/Infrastructure.csproj index 6d03f1620..fd7ffa5c0 100644 --- a/account-management/src/Infrastructure/Infrastructure.csproj +++ b/account-management/Infrastructure/Infrastructure.csproj @@ -9,6 +9,7 @@ + diff --git a/account-management/src/Infrastructure/InfrastructureConfiguration.cs b/account-management/Infrastructure/InfrastructureConfiguration.cs similarity index 77% rename from account-management/src/Infrastructure/InfrastructureConfiguration.cs rename to account-management/Infrastructure/InfrastructureConfiguration.cs index 3e1fb6c7d..0d496fef5 100644 --- a/account-management/src/Infrastructure/InfrastructureConfiguration.cs +++ b/account-management/Infrastructure/InfrastructureConfiguration.cs @@ -1,7 +1,7 @@ using System.Reflection; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using PlatformPlatform.Foundation; +using PlatformPlatform.Foundation.InfrastructureCore; namespace PlatformPlatform.AccountManagement.Infrastructure; @@ -16,9 +16,9 @@ public static class InfrastructureConfiguration public static IServiceCollection AddInfrastructureServices(this IServiceCollection services, IConfiguration configuration) { - services.ConfigureDatabaseContext(configuration); - - services.RegisterRepositories(Assembly); + services + .ConfigureDatabaseContext(configuration) + .RegisterRepositories(Assembly); return services; } diff --git a/account-management/src/Infrastructure/Migrations/20230429131456_Initial.Designer.cs b/account-management/Infrastructure/Migrations/20230429131456_Initial.Designer.cs similarity index 100% rename from account-management/src/Infrastructure/Migrations/20230429131456_Initial.Designer.cs rename to account-management/Infrastructure/Migrations/20230429131456_Initial.Designer.cs diff --git a/account-management/src/Infrastructure/Migrations/20230429131456_Initial.cs b/account-management/Infrastructure/Migrations/20230429131456_Initial.cs similarity index 100% rename from account-management/src/Infrastructure/Migrations/20230429131456_Initial.cs rename to account-management/Infrastructure/Migrations/20230429131456_Initial.cs diff --git a/account-management/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs b/account-management/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs similarity index 100% rename from account-management/src/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs rename to account-management/Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs diff --git a/account-management/Infrastructure/Tenants/TenantRepository.cs b/account-management/Infrastructure/Tenants/TenantRepository.cs new file mode 100644 index 000000000..3704351af --- /dev/null +++ b/account-management/Infrastructure/Tenants/TenantRepository.cs @@ -0,0 +1,18 @@ +using Microsoft.EntityFrameworkCore; +using PlatformPlatform.AccountManagement.Domain.Tenants; +using PlatformPlatform.Foundation.InfrastructureCore.Persistence; + +namespace PlatformPlatform.AccountManagement.Infrastructure.Tenants; + +public sealed class TenantRepository : RepositoryBase, ITenantRepository +{ + // ReSharper disable once SuggestBaseTypeForParameterInConstructor + public TenantRepository(ApplicationDbContext applicationDbContext) : base(applicationDbContext) + { + } + + public Task IsSubdomainFreeAsync(string subdomain, CancellationToken cancellationToken) + { + return DbSet.AllAsync(tenant => tenant.Subdomain != subdomain, cancellationToken); + } +} \ No newline at end of file diff --git a/account-management/tests/Tests/Application/Tenants/Commands/CreateTenant/CreateTenantCommandHandlerTests.cs b/account-management/Tests/Application/Tenants/Commands/CreateTenant/CreateTenantCommandHandlerTests.cs similarity index 100% rename from account-management/tests/Tests/Application/Tenants/Commands/CreateTenant/CreateTenantCommandHandlerTests.cs rename to account-management/Tests/Application/Tenants/Commands/CreateTenant/CreateTenantCommandHandlerTests.cs diff --git a/account-management/tests/Tests/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommandHandlerTests.cs b/account-management/Tests/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommandHandlerTests.cs similarity index 100% rename from account-management/tests/Tests/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommandHandlerTests.cs rename to account-management/Tests/Application/Tenants/Commands/DeleteTenant/DeleteTenantCommandHandlerTests.cs diff --git a/account-management/tests/Tests/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommandHandlerTests.cs b/account-management/Tests/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommandHandlerTests.cs similarity index 100% rename from account-management/tests/Tests/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommandHandlerTests.cs rename to account-management/Tests/Application/Tenants/Commands/UpdateTenant/UpdateTenantCommandHandlerTests.cs diff --git a/account-management/tests/Tests/Application/Tenants/Queries/GetTenantByIdQueryTests.cs b/account-management/Tests/Application/Tenants/Queries/GetTenantByIdQueryTests.cs similarity index 100% rename from account-management/tests/Tests/Application/Tenants/Queries/GetTenantByIdQueryTests.cs rename to account-management/Tests/Application/Tenants/Queries/GetTenantByIdQueryTests.cs diff --git a/account-management/tests/Tests/ArchitectureTests/DependencyTests.cs b/account-management/Tests/ArchitectureTests/DependencyTests.cs similarity index 100% rename from account-management/tests/Tests/ArchitectureTests/DependencyTests.cs rename to account-management/Tests/ArchitectureTests/DependencyTests.cs diff --git a/account-management/tests/Tests/ArchitectureTests/PublicClassesTests.cs b/account-management/Tests/ArchitectureTests/PublicClassesTests.cs similarity index 97% rename from account-management/tests/Tests/ArchitectureTests/PublicClassesTests.cs rename to account-management/Tests/ArchitectureTests/PublicClassesTests.cs index aedd50249..ddddaecb5 100644 --- a/account-management/tests/Tests/ArchitectureTests/PublicClassesTests.cs +++ b/account-management/Tests/ArchitectureTests/PublicClassesTests.cs @@ -3,7 +3,7 @@ using PlatformPlatform.AccountManagement.Application; using PlatformPlatform.AccountManagement.Domain; using PlatformPlatform.AccountManagement.Infrastructure; -using PlatformPlatform.Foundation.Application; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; using Xunit; namespace PlatformPlatform.AccountManagement.Tests.ArchitectureTests; diff --git a/account-management/tests/Tests/DatabaseSeeder.cs b/account-management/Tests/DatabaseSeeder.cs similarity index 100% rename from account-management/tests/Tests/DatabaseSeeder.cs rename to account-management/Tests/DatabaseSeeder.cs diff --git a/account-management/tests/Tests/Domain/TenantTests.cs b/account-management/Tests/Domain/TenantTests.cs similarity index 100% rename from account-management/tests/Tests/Domain/TenantTests.cs rename to account-management/Tests/Domain/TenantTests.cs diff --git a/account-management/tests/Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs b/account-management/Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs similarity index 100% rename from account-management/tests/Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs rename to account-management/Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs diff --git a/account-management/tests/Tests/Infrastructure/Tenants/TenantRepositoryTests.cs b/account-management/Tests/Infrastructure/Tenants/TenantRepositoryTests.cs similarity index 100% rename from account-management/tests/Tests/Infrastructure/Tenants/TenantRepositoryTests.cs rename to account-management/Tests/Infrastructure/Tenants/TenantRepositoryTests.cs diff --git a/account-management/tests/Tests/Tests.csproj b/account-management/Tests/Tests.csproj similarity index 79% rename from account-management/tests/Tests/Tests.csproj rename to account-management/Tests/Tests.csproj index 372ac402c..4bca77bf8 100644 --- a/account-management/tests/Tests/Tests.csproj +++ b/account-management/Tests/Tests.csproj @@ -12,10 +12,10 @@ - - - - + + + + @@ -25,7 +25,6 @@ - diff --git a/account-management/tests/Tests/WebApi/Shared/CustomExceptionHandlingTests.cs b/account-management/Tests/WebApi/AspNetCoreUtils/CustomExceptionHandlingTests.cs similarity index 96% rename from account-management/tests/Tests/WebApi/Shared/CustomExceptionHandlingTests.cs rename to account-management/Tests/WebApi/AspNetCoreUtils/CustomExceptionHandlingTests.cs index 8faea022d..0168259b2 100644 --- a/account-management/tests/Tests/WebApi/Shared/CustomExceptionHandlingTests.cs +++ b/account-management/Tests/WebApi/AspNetCoreUtils/CustomExceptionHandlingTests.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Mvc.Testing; using Xunit; -namespace PlatformPlatform.AccountManagement.Tests.WebApi.Shared; +namespace PlatformPlatform.AccountManagement.Tests.WebApi.AspNetCoreUtils; public class CustomExceptionHandlingTests { diff --git a/account-management/tests/Tests/WebApi/Endpoints/TenantEndpointsTests.cs b/account-management/Tests/WebApi/Endpoints/TenantEndpointsTests.cs similarity index 99% rename from account-management/tests/Tests/WebApi/Endpoints/TenantEndpointsTests.cs rename to account-management/Tests/WebApi/Endpoints/TenantEndpointsTests.cs index eebc11b9c..539be10a5 100644 --- a/account-management/tests/Tests/WebApi/Endpoints/TenantEndpointsTests.cs +++ b/account-management/Tests/WebApi/Endpoints/TenantEndpointsTests.cs @@ -10,7 +10,7 @@ using PlatformPlatform.AccountManagement.Infrastructure; using PlatformPlatform.AccountManagement.Tests.Infrastructure; using PlatformPlatform.AccountManagement.WebApi.Endpoints; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Validation; using Xunit; namespace PlatformPlatform.AccountManagement.Tests.WebApi.Endpoints; diff --git a/account-management/src/WebApi/Endpoints/TenantEndpoints.cs b/account-management/WebApi/Endpoints/TenantEndpoints.cs similarity index 96% rename from account-management/src/WebApi/Endpoints/TenantEndpoints.cs rename to account-management/WebApi/Endpoints/TenantEndpoints.cs index 63bf208b0..39542c33a 100644 --- a/account-management/src/WebApi/Endpoints/TenantEndpoints.cs +++ b/account-management/WebApi/Endpoints/TenantEndpoints.cs @@ -4,7 +4,7 @@ using PlatformPlatform.AccountManagement.Application.Tenants.Commands.UpdateTenant; using PlatformPlatform.AccountManagement.Application.Tenants.Queries; using PlatformPlatform.AccountManagement.Domain.Tenants; -using PlatformPlatform.Foundation.WebApi; +using PlatformPlatform.Foundation.AspNetCoreUtils; namespace PlatformPlatform.AccountManagement.WebApi.Endpoints; diff --git a/account-management/src/WebApi/Endpoints/TestEndpoints.cs b/account-management/WebApi/Endpoints/TestEndpoints.cs similarity index 100% rename from account-management/src/WebApi/Endpoints/TestEndpoints.cs rename to account-management/WebApi/Endpoints/TestEndpoints.cs diff --git a/account-management/src/WebApi/Program.cs b/account-management/WebApi/Program.cs similarity index 92% rename from account-management/src/WebApi/Program.cs rename to account-management/WebApi/Program.cs index 3a410f408..859d0ed59 100644 --- a/account-management/src/WebApi/Program.cs +++ b/account-management/WebApi/Program.cs @@ -2,14 +2,12 @@ using PlatformPlatform.AccountManagement.Infrastructure; using PlatformPlatform.AccountManagement.WebApi; using PlatformPlatform.AccountManagement.WebApi.Endpoints; -using PlatformPlatform.Foundation; -using PlatformPlatform.Foundation.WebApi; +using PlatformPlatform.Foundation.AspNetCoreUtils; var builder = WebApplication.CreateBuilder(args); // Configure services for the Application, Infrastructure, and WebApi layers. builder.Services - .AddFoundationServices() .AddApplicationServices() .AddInfrastructureServices(builder.Configuration) .AddWebApiServices(); diff --git a/account-management/src/WebApi/Properties/launchSettings.json b/account-management/WebApi/Properties/launchSettings.json similarity index 100% rename from account-management/src/WebApi/Properties/launchSettings.json rename to account-management/WebApi/Properties/launchSettings.json diff --git a/account-management/src/WebApi/WebApi.csproj b/account-management/WebApi/WebApi.csproj similarity index 91% rename from account-management/src/WebApi/WebApi.csproj rename to account-management/WebApi/WebApi.csproj index 9fe777e1a..e6543c246 100644 --- a/account-management/src/WebApi/WebApi.csproj +++ b/account-management/WebApi/WebApi.csproj @@ -9,6 +9,7 @@ + diff --git a/account-management/src/WebApi/WebApiConfiguration.cs b/account-management/WebApi/WebApiConfiguration.cs similarity index 94% rename from account-management/src/WebApi/WebApiConfiguration.cs rename to account-management/WebApi/WebApiConfiguration.cs index 51ba541c8..a9a8446da 100644 --- a/account-management/src/WebApi/WebApiConfiguration.cs +++ b/account-management/WebApi/WebApiConfiguration.cs @@ -1,7 +1,7 @@ using System.Reflection; using JetBrains.Annotations; using Microsoft.OpenApi.Models; -using PlatformPlatform.Foundation.WebApi; +using PlatformPlatform.Foundation.AspNetCoreUtils; namespace PlatformPlatform.AccountManagement.WebApi; diff --git a/account-management/src/WebApi/appsettings.json b/account-management/WebApi/appsettings.json similarity index 100% rename from account-management/src/WebApi/appsettings.json rename to account-management/WebApi/appsettings.json diff --git a/account-management/src/Foundation/Domain/Result.cs b/account-management/src/Foundation/Domain/Result.cs deleted file mode 100644 index 3bf112e98..000000000 --- a/account-management/src/Foundation/Domain/Result.cs +++ /dev/null @@ -1,26 +0,0 @@ -using JetBrains.Annotations; - -namespace PlatformPlatform.Foundation.Domain; - -[UsedImplicitly] -public sealed record PropertyError(string? PropertyName, string Message); - -public sealed class Result -{ - private Result(PropertyError[]? errors) - { - Errors = errors ?? Array.Empty(); - } - - public PropertyError[] Errors { get; } - - public static Result Success() - { - return new Result(null); - } - - public static Result Failure(string name, string error) - { - return new Result(new[] {new PropertyError(name, error)}); - } -} \ No newline at end of file diff --git a/account-management/src/Infrastructure/Tenants/TenantRepository.cs b/account-management/src/Infrastructure/Tenants/TenantRepository.cs deleted file mode 100644 index f3e2f3fa2..000000000 --- a/account-management/src/Infrastructure/Tenants/TenantRepository.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using PlatformPlatform.AccountManagement.Domain.Tenants; - -namespace PlatformPlatform.AccountManagement.Infrastructure.Tenants; - -public sealed class TenantRepository : ITenantRepository -{ - private readonly DbSet _tenantDbSet; - - public TenantRepository(ApplicationDbContext applicationDbContext) - { - _tenantDbSet = applicationDbContext.Tenants; - } - - public async Task GetByIdAsync(TenantId id, CancellationToken cancellationToken) - { - return await _tenantDbSet.FindAsync(new object?[] {id}, cancellationToken); - } - - public void Add(Tenant tenant) - { - _tenantDbSet.Add(tenant); - } - - public void Update(Tenant tenant) - { - _tenantDbSet.Update(tenant); - } - - public void Remove(Tenant tenant) - { - _tenantDbSet.Remove(tenant); - } - - public Task IsSubdomainFreeAsync(string subdomain, CancellationToken cancellationToken) - { - return _tenantDbSet.AllAsync(tenant => tenant.Subdomain != subdomain, cancellationToken); - } -} \ No newline at end of file diff --git a/account-management/tests/Foundation.Tests/TestEntities/TestAggregateRepository.cs b/account-management/tests/Foundation.Tests/TestEntities/TestAggregateRepository.cs deleted file mode 100644 index fdb2168ab..000000000 --- a/account-management/tests/Foundation.Tests/TestEntities/TestAggregateRepository.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Domain; - -namespace PlatformPlatform.Foundation.Tests.TestEntities; - -public class TestAggregateRepository : IRepository -{ - private readonly DbSet _testAggregatesDbSet; - - public TestAggregateRepository(TestDbContext testDbContext) - { - _testAggregatesDbSet = testDbContext.TestAggregates; - } - - public async Task GetByIdAsync(long id, CancellationToken cancellationToken) - { - return await _testAggregatesDbSet.FindAsync(new object?[] {id}, cancellationToken); - } - - public void Add(TestAggregate aggregate) - { - _testAggregatesDbSet.Add(aggregate); - } - - public void Update(TestAggregate aggregate) - { - _testAggregatesDbSet.Update(aggregate); - } - - public void Remove(TestAggregate aggregate) - { - _testAggregatesDbSet.Remove(aggregate); - } -} \ No newline at end of file diff --git a/backend-foundation/AspNetCoreUtils/AspNetCoreUtils.csproj b/backend-foundation/AspNetCoreUtils/AspNetCoreUtils.csproj new file mode 100644 index 000000000..d965aeaee --- /dev/null +++ b/backend-foundation/AspNetCoreUtils/AspNetCoreUtils.csproj @@ -0,0 +1,25 @@ + + + + net7.0 + enable + enable + PlatformPlatform.Foundation.AspNetCoreUtils + PlatformPlatform.Foundation.AspNetCoreUtils + + + + + + + + + + + + + + + + + diff --git a/account-management/src/Foundation/WebApi/CommandResultExtensions.cs b/backend-foundation/AspNetCoreUtils/CommandResultExtensions.cs similarity index 82% rename from account-management/src/Foundation/WebApi/CommandResultExtensions.cs rename to backend-foundation/AspNetCoreUtils/CommandResultExtensions.cs index 745960f5c..e34fed14f 100644 --- a/account-management/src/Foundation/WebApi/CommandResultExtensions.cs +++ b/backend-foundation/AspNetCoreUtils/CommandResultExtensions.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Http; -using PlatformPlatform.Foundation.Application; +using PlatformPlatform.Foundation.DomainModeling.Cqrs; -namespace PlatformPlatform.Foundation.WebApi; +namespace PlatformPlatform.Foundation.AspNetCoreUtils; public static class CommandResultExtensions { diff --git a/account-management/src/Foundation/WebApi/GlobalExceptionHandlerMiddleware.cs b/backend-foundation/AspNetCoreUtils/GlobalExceptionHandlerMiddleware.cs similarity index 95% rename from account-management/src/Foundation/WebApi/GlobalExceptionHandlerMiddleware.cs rename to backend-foundation/AspNetCoreUtils/GlobalExceptionHandlerMiddleware.cs index 21fb4ef7d..53b350e4a 100644 --- a/account-management/src/Foundation/WebApi/GlobalExceptionHandlerMiddleware.cs +++ b/backend-foundation/AspNetCoreUtils/GlobalExceptionHandlerMiddleware.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -namespace PlatformPlatform.Foundation.WebApi; +namespace PlatformPlatform.Foundation.AspNetCoreUtils; public sealed class GlobalExceptionHandlerMiddleware : IMiddleware { diff --git a/account-management/src/Foundation/Application/DomainEvents/PublishDomainEventsPipelineBehavior.cs b/backend-foundation/DomainModeling/Behaviors/PublishDomainEventsPipelineBehavior.cs similarity index 93% rename from account-management/src/Foundation/Application/DomainEvents/PublishDomainEventsPipelineBehavior.cs rename to backend-foundation/DomainModeling/Behaviors/PublishDomainEventsPipelineBehavior.cs index 321c54f8e..773f523fb 100644 --- a/account-management/src/Foundation/Application/DomainEvents/PublishDomainEventsPipelineBehavior.cs +++ b/backend-foundation/DomainModeling/Behaviors/PublishDomainEventsPipelineBehavior.cs @@ -1,7 +1,8 @@ using MediatR; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.DomainEvents; +using PlatformPlatform.Foundation.DomainModeling.Persistence; -namespace PlatformPlatform.Foundation.Application.DomainEvents; +namespace PlatformPlatform.Foundation.DomainModeling.Behaviors; /// /// This method publishes any domain events that were generated during the execution of a command (and added to diff --git a/account-management/src/Foundation/Application/Persistence/UnitOfWorkPipelineBehavior.cs b/backend-foundation/DomainModeling/Behaviors/UnitOfWorkPipelineBehavior.cs similarity index 89% rename from account-management/src/Foundation/Application/Persistence/UnitOfWorkPipelineBehavior.cs rename to backend-foundation/DomainModeling/Behaviors/UnitOfWorkPipelineBehavior.cs index e44744d58..de2901c3a 100644 --- a/account-management/src/Foundation/Application/Persistence/UnitOfWorkPipelineBehavior.cs +++ b/backend-foundation/DomainModeling/Behaviors/UnitOfWorkPipelineBehavior.cs @@ -1,7 +1,7 @@ using MediatR; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Persistence; -namespace PlatformPlatform.Foundation.Application.Persistence; +namespace PlatformPlatform.Foundation.DomainModeling.Behaviors; /// /// The UnitOfWorkPipelineBehavior class is a MediatR pipeline behavior that encapsulates the unit of work pattern. diff --git a/account-management/src/Foundation/Application/CommandResult.cs b/backend-foundation/DomainModeling/Cqrs/CommandResult.cs similarity index 94% rename from account-management/src/Foundation/Application/CommandResult.cs rename to backend-foundation/DomainModeling/Cqrs/CommandResult.cs index 7c7a7116d..f651f7713 100644 --- a/account-management/src/Foundation/Application/CommandResult.cs +++ b/backend-foundation/DomainModeling/Cqrs/CommandResult.cs @@ -1,8 +1,8 @@ using System.Net; using JetBrains.Annotations; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Validation; -namespace PlatformPlatform.Foundation.Application; +namespace PlatformPlatform.Foundation.DomainModeling.Cqrs; /// /// All commands should return a . This is used to indicate if the command was diff --git a/account-management/src/Foundation/Application/QueryResult.cs b/backend-foundation/DomainModeling/Cqrs/QueryResult.cs similarity index 96% rename from account-management/src/Foundation/Application/QueryResult.cs rename to backend-foundation/DomainModeling/Cqrs/QueryResult.cs index 91c2a57ff..faee98cb9 100644 --- a/account-management/src/Foundation/Application/QueryResult.cs +++ b/backend-foundation/DomainModeling/Cqrs/QueryResult.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace PlatformPlatform.Foundation.Application; +namespace PlatformPlatform.Foundation.DomainModeling.Cqrs; [UsedImplicitly] public sealed record QueryError(string Message); diff --git a/account-management/src/Foundation/Domain/IDomainEvent.cs b/backend-foundation/DomainModeling/DomainEvents/IDomainEvent.cs similarity index 95% rename from account-management/src/Foundation/Domain/IDomainEvent.cs rename to backend-foundation/DomainModeling/DomainEvents/IDomainEvent.cs index f40943e35..84d6656ac 100644 --- a/account-management/src/Foundation/Domain/IDomainEvent.cs +++ b/backend-foundation/DomainModeling/DomainEvents/IDomainEvent.cs @@ -1,6 +1,6 @@ using MediatR; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.DomainEvents; /// /// The DomainEvent interface represents a domain event that occurred in the domain. The DomainEvent implements the diff --git a/backend-foundation/DomainModeling/DomainModeling.csproj b/backend-foundation/DomainModeling/DomainModeling.csproj new file mode 100644 index 000000000..dce5218fd --- /dev/null +++ b/backend-foundation/DomainModeling/DomainModeling.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + PlatformPlatform.Foundation.DomainModeling + PlatformPlatform.Foundation.DomainModeling + + + + + + + + + diff --git a/backend-foundation/DomainModeling/DomainModelingConfiguration.cs b/backend-foundation/DomainModeling/DomainModelingConfiguration.cs new file mode 100644 index 000000000..77260fd7a --- /dev/null +++ b/backend-foundation/DomainModeling/DomainModelingConfiguration.cs @@ -0,0 +1,16 @@ +using MediatR; +using Microsoft.Extensions.DependencyInjection; +using PlatformPlatform.Foundation.DomainModeling.Behaviors; + +namespace PlatformPlatform.Foundation.DomainModeling; + +public static class DomainModelingConfiguration +{ + public static IServiceCollection AddDomainModelingServices(this IServiceCollection services) + { + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnitOfWorkPipelineBehavior<,>)); + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(PublishDomainEventsPipelineBehavior<,>)); + + return services; + } +} \ No newline at end of file diff --git a/account-management/src/Foundation/Domain/AggregateRoot.cs b/backend-foundation/DomainModeling/Entities/AggregateRoot.cs similarity index 92% rename from account-management/src/Foundation/Domain/AggregateRoot.cs rename to backend-foundation/DomainModeling/Entities/AggregateRoot.cs index e1315eb7a..5acf49440 100644 --- a/account-management/src/Foundation/Domain/AggregateRoot.cs +++ b/backend-foundation/DomainModeling/Entities/AggregateRoot.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations.Schema; +using PlatformPlatform.Foundation.DomainModeling.DomainEvents; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Entities; /// /// Interface for aggregate roots, which also implements IAuditableEntity. Aggregate roots are a concept in diff --git a/account-management/src/Foundation/Domain/AudibleEntity.cs b/backend-foundation/DomainModeling/Entities/AudibleEntity.cs similarity index 93% rename from account-management/src/Foundation/Domain/AudibleEntity.cs rename to backend-foundation/DomainModeling/Entities/AudibleEntity.cs index 2fff7d7df..4e5141ff5 100644 --- a/account-management/src/Foundation/Domain/AudibleEntity.cs +++ b/backend-foundation/DomainModeling/Entities/AudibleEntity.cs @@ -1,7 +1,7 @@ using System.ComponentModel.DataAnnotations; using JetBrains.Annotations; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Entities; /// /// The AudibleEntity class extends Entity and implements IAuditableEntity, which adds diff --git a/account-management/src/Foundation/Domain/Entity.cs b/backend-foundation/DomainModeling/Entities/Entity.cs similarity index 92% rename from account-management/src/Foundation/Domain/Entity.cs rename to backend-foundation/DomainModeling/Entities/Entity.cs index 9344dc7ed..d762e3084 100644 --- a/account-management/src/Foundation/Domain/Entity.cs +++ b/backend-foundation/DomainModeling/Entities/Entity.cs @@ -1,7 +1,8 @@ using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; +using PlatformPlatform.Foundation.DomainModeling.Identity; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Entities; /// /// The Entity class is a base class for entities which represents business objects. diff --git a/account-management/src/Foundation/Domain/EntityEqualityComparer.cs b/backend-foundation/DomainModeling/Entities/EntityEqualityComparer.cs similarity index 88% rename from account-management/src/Foundation/Domain/EntityEqualityComparer.cs rename to backend-foundation/DomainModeling/Entities/EntityEqualityComparer.cs index db43c12e2..ae698c220 100644 --- a/account-management/src/Foundation/Domain/EntityEqualityComparer.cs +++ b/backend-foundation/DomainModeling/Entities/EntityEqualityComparer.cs @@ -1,4 +1,4 @@ -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Entities; public sealed class EntityEqualityComparer : IEqualityComparer> where T : IComparable { diff --git a/account-management/src/Foundation/Domain/IAuditableEntity.cs b/backend-foundation/DomainModeling/Entities/IAuditableEntity.cs similarity index 86% rename from account-management/src/Foundation/Domain/IAuditableEntity.cs rename to backend-foundation/DomainModeling/Entities/IAuditableEntity.cs index bfc28fb0f..659b28732 100644 --- a/account-management/src/Foundation/Domain/IAuditableEntity.cs +++ b/backend-foundation/DomainModeling/Entities/IAuditableEntity.cs @@ -1,6 +1,6 @@ using JetBrains.Annotations; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Entities; /// /// IAuditableEntity interface contains properties and methods for maintaining audit information for when diff --git a/account-management/src/Foundation/Domain/IdGenerator.cs b/backend-foundation/DomainModeling/Identity/IdGenerator.cs similarity index 97% rename from account-management/src/Foundation/Domain/IdGenerator.cs rename to backend-foundation/DomainModeling/Identity/IdGenerator.cs index c81b28971..dafbae57d 100644 --- a/account-management/src/Foundation/Domain/IdGenerator.cs +++ b/backend-foundation/DomainModeling/Identity/IdGenerator.cs @@ -1,7 +1,7 @@ using System.Net; using System.Net.Sockets; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Identity; /// /// IdGenerator is a utility that can generate IDs in a low-latency, distributed, uncoordinated, roughly diff --git a/account-management/src/Foundation/Domain/StronglyTypedId.cs b/backend-foundation/DomainModeling/Identity/StronglyTypedId.cs similarity index 62% rename from account-management/src/Foundation/Domain/StronglyTypedId.cs rename to backend-foundation/DomainModeling/Identity/StronglyTypedId.cs index 4f587265d..8d85e7f55 100644 --- a/account-management/src/Foundation/Domain/StronglyTypedId.cs +++ b/backend-foundation/DomainModeling/Identity/StronglyTypedId.cs @@ -1,32 +1,4 @@ -using System.Reflection; - -namespace PlatformPlatform.Foundation.Domain; - -/// -/// This is a special version of for longs which is the recommended type to use. -/// It uses the to create IDs that are chronological and guaranteed to be unique. -/// -public abstract record StronglyTypedId(long Value) : StronglyTypedId(Value) - where T : StronglyTypedId -{ - public static T NewId() - { - var newValue = IdGenerator.NewId(); - return FormLong(newValue); - } - - public static T FromString(string value) - { - var newValue = Convert.ToInt64(value); - return FormLong(newValue); - } - - private static T FormLong(long newValue) - { - return (T) Activator.CreateInstance(typeof(T), - BindingFlags.Instance | BindingFlags.Public, null, new object[] {newValue}, null)!; - } -} +namespace PlatformPlatform.Foundation.DomainModeling.Identity; /// /// StronglyTypedId is an abstract record type for creating strongly typed IDs with a specified value type. It makes diff --git a/backend-foundation/DomainModeling/Identity/StronglyTypedLongIdcs.cs b/backend-foundation/DomainModeling/Identity/StronglyTypedLongIdcs.cs new file mode 100644 index 000000000..c28f735c2 --- /dev/null +++ b/backend-foundation/DomainModeling/Identity/StronglyTypedLongIdcs.cs @@ -0,0 +1,29 @@ +using System.Reflection; + +namespace PlatformPlatform.Foundation.DomainModeling.Identity; + +/// +/// This is a special version of for longs which is the recommended type to use. +/// It uses the to create IDs that are chronological and guaranteed to be unique. +/// +public abstract record StronglyTypedId(long Value) : StronglyTypedId(Value) + where T : StronglyTypedId +{ + public static T NewId() + { + var newValue = IdGenerator.NewId(); + return FormLong(newValue); + } + + public static T FromString(string value) + { + var newValue = Convert.ToInt64(value); + return FormLong(newValue); + } + + private static T FormLong(long newValue) + { + return (T) Activator.CreateInstance(typeof(T), + BindingFlags.Instance | BindingFlags.Public, null, new object[] {newValue}, null)!; + } +} \ No newline at end of file diff --git a/account-management/src/Foundation/Domain/IRepository.cs b/backend-foundation/DomainModeling/Persistence/IRepository.cs similarity index 90% rename from account-management/src/Foundation/Domain/IRepository.cs rename to backend-foundation/DomainModeling/Persistence/IRepository.cs index d4ecb1934..0d0f1ff06 100644 --- a/account-management/src/Foundation/Domain/IRepository.cs +++ b/backend-foundation/DomainModeling/Persistence/IRepository.cs @@ -1,6 +1,7 @@ using JetBrains.Annotations; +using PlatformPlatform.Foundation.DomainModeling.Entities; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Persistence; /// /// IRepository is a generic interface for repositories. Repositories are a DDD concept, and are used diff --git a/account-management/src/Foundation/Domain/IUnitOfWork.cs b/backend-foundation/DomainModeling/Persistence/IUnitOfWork.cs similarity index 85% rename from account-management/src/Foundation/Domain/IUnitOfWork.cs rename to backend-foundation/DomainModeling/Persistence/IUnitOfWork.cs index e26336824..1d3485c0b 100644 --- a/account-management/src/Foundation/Domain/IUnitOfWork.cs +++ b/backend-foundation/DomainModeling/Persistence/IUnitOfWork.cs @@ -1,4 +1,6 @@ -namespace PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; + +namespace PlatformPlatform.Foundation.DomainModeling.Persistence; /// /// IUnitOfWork interface provides a method for committing changes made within the unit of work. diff --git a/backend-foundation/DomainModeling/Validation/ValidationResult.cs b/backend-foundation/DomainModeling/Validation/ValidationResult.cs new file mode 100644 index 000000000..02a5027a7 --- /dev/null +++ b/backend-foundation/DomainModeling/Validation/ValidationResult.cs @@ -0,0 +1,26 @@ +using JetBrains.Annotations; + +namespace PlatformPlatform.Foundation.DomainModeling.Validation; + +[UsedImplicitly] +public sealed record PropertyError(string? PropertyName, string Message); + +public sealed class ValidationResult +{ + private ValidationResult(PropertyError[]? errors) + { + Errors = errors ?? Array.Empty(); + } + + public PropertyError[] Errors { get; } + + public static ValidationResult Success() + { + return new ValidationResult(null); + } + + public static ValidationResult Failure(string name, string error) + { + return new ValidationResult(new[] {new PropertyError(name, error)}); + } +} \ No newline at end of file diff --git a/account-management/src/Foundation/Domain/ValidationUtils.cs b/backend-foundation/DomainModeling/Validation/ValidationUtils.cs similarity index 70% rename from account-management/src/Foundation/Domain/ValidationUtils.cs rename to backend-foundation/DomainModeling/Validation/ValidationUtils.cs index 4c85ef4d8..d6710f809 100644 --- a/account-management/src/Foundation/Domain/ValidationUtils.cs +++ b/backend-foundation/DomainModeling/Validation/ValidationUtils.cs @@ -1,23 +1,24 @@ using System.Text.RegularExpressions; -namespace PlatformPlatform.Foundation.Domain; +namespace PlatformPlatform.Foundation.DomainModeling.Validation; /// /// The ValidationUtils class is a static utility class that provides methods for validating various types of input /// data such as strings, phone numbers, and email addresses. These methods are used for validating the data of -/// domain entities and commands. The methods return a object, which is used to determine if -/// the input is valid or not. If the input is not valid, the object contains an error message -/// that can be used to inform the user of the error. +/// domain entities and commands. The methods return a object, which is used to +/// determine if the input is valid or not. If the input is not valid, the object +/// contains an error message that can be used to inform the user of the error. /// public static partial class ValidationUtils { - public static Result IsStringValid(string name, string input, int minLength, int maxLength, string errorMessage) + public static ValidationResult IsStringValid(string name, string input, int minLength, int maxLength, + string errorMessage) { var isSuccess = input.Length >= minLength && input.Length <= maxLength; return GetResult(name, isSuccess, errorMessage); } - public static Result IsStringValid(string name, string input, string regEx, int minLength, int maxLength, + public static ValidationResult IsStringValid(string name, string input, string regEx, int minLength, int maxLength, string errorMessage) { var isLengthOk = input.Length >= minLength && input.Length <= maxLength; @@ -25,7 +26,7 @@ public static Result IsStringValid(string name, string input, int minLength, int return GetResult(name, isLengthOk && isRegExOk, errorMessage); } - public static Result IsValidPhone(string name, string? input) + public static ValidationResult IsValidPhone(string name, string? input) { // The ITU-T Recommendation E.164 limits phone numbers to 15 digits (including country code). // We add 5 extra characters to allow for spaces, dashes, parentheses, etc. @@ -40,7 +41,7 @@ public static Result IsValidPhone(string name, string? input) [GeneratedRegex(@"^\+?(\d[\d-. ]+)?(\([\d-. ]+\))?[\d-. ]+\d$")] private static partial Regex PhoneRegex(); - public static Result IsValidEmail(string name, string input) + public static ValidationResult IsValidEmail(string name, string input) { // While emails can be longer, we will limit them to 100 characters which should be enough for most cases const int emailMaxLength = 100; @@ -54,10 +55,10 @@ public static Result IsValidEmail(string name, string input) [GeneratedRegex(@"^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$")] private static partial Regex EmailRegex(); - private static Result GetResult(string name, bool success, string errorMessage) + private static ValidationResult GetResult(string name, bool success, string errorMessage) { return success - ? Result.Success() - : Result.Failure(name, errorMessage); + ? ValidationResult.Success() + : ValidationResult.Failure(name, errorMessage); } } \ No newline at end of file diff --git a/account-management/src/Foundation/Infrastructure/FoundationDbContext.cs b/backend-foundation/InfrastructureCore/EntityFramework/FoundationDbContext.cs similarity index 88% rename from account-management/src/Foundation/Infrastructure/FoundationDbContext.cs rename to backend-foundation/InfrastructureCore/EntityFramework/FoundationDbContext.cs index eaa02f843..2bdc6469d 100644 --- a/account-management/src/Foundation/Infrastructure/FoundationDbContext.cs +++ b/backend-foundation/InfrastructureCore/EntityFramework/FoundationDbContext.cs @@ -1,7 +1,7 @@ using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; -namespace PlatformPlatform.Foundation.Infrastructure; +namespace PlatformPlatform.Foundation.InfrastructureCore.EntityFramework; /// /// The FoundationDbContext class represents the Entity Framework Core DbContext for managing data access to the diff --git a/account-management/src/Foundation/Infrastructure/ModelBuilderExtensions.cs b/backend-foundation/InfrastructureCore/EntityFramework/ModelBuilderExtensions.cs similarity index 88% rename from account-management/src/Foundation/Infrastructure/ModelBuilderExtensions.cs rename to backend-foundation/InfrastructureCore/EntityFramework/ModelBuilderExtensions.cs index be730f5da..8d03d5195 100644 --- a/account-management/src/Foundation/Infrastructure/ModelBuilderExtensions.cs +++ b/backend-foundation/InfrastructureCore/EntityFramework/ModelBuilderExtensions.cs @@ -2,9 +2,10 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Identity; -namespace PlatformPlatform.Foundation.Infrastructure; +namespace PlatformPlatform.Foundation.InfrastructureCore.EntityFramework; public static class ModelBuilderExtensions { diff --git a/account-management/src/Foundation/Infrastructure/UpdateAuditableEntitiesInterceptor.cs b/backend-foundation/InfrastructureCore/EntityFramework/UpdateAuditableEntitiesInterceptor.cs similarity index 92% rename from account-management/src/Foundation/Infrastructure/UpdateAuditableEntitiesInterceptor.cs rename to backend-foundation/InfrastructureCore/EntityFramework/UpdateAuditableEntitiesInterceptor.cs index adf035e68..1710dc6a8 100644 --- a/account-management/src/Foundation/Infrastructure/UpdateAuditableEntitiesInterceptor.cs +++ b/backend-foundation/InfrastructureCore/EntityFramework/UpdateAuditableEntitiesInterceptor.cs @@ -1,8 +1,8 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; -namespace PlatformPlatform.Foundation.Infrastructure; +namespace PlatformPlatform.Foundation.InfrastructureCore.EntityFramework; /// /// The UpdateAuditableEntitiesInterceptor is a SaveChangesInterceptor that updates the ModifiedAt property diff --git a/account-management/src/Foundation/Foundation.csproj b/backend-foundation/InfrastructureCore/InfrastructureCore.csproj similarity index 62% rename from account-management/src/Foundation/Foundation.csproj rename to backend-foundation/InfrastructureCore/InfrastructureCore.csproj index 80a4fd875..a1153c206 100644 --- a/account-management/src/Foundation/Foundation.csproj +++ b/backend-foundation/InfrastructureCore/InfrastructureCore.csproj @@ -2,21 +2,13 @@ net7.0 - PlatformPlatform.Foundation - PlatformPlatform.Foundation enable enable + PlatformPlatform.Foundation.InfrastructureCore + PlatformPlatform.Foundation.InfrastructureCore - - - - - - - - @@ -26,4 +18,8 @@ + + + + diff --git a/backend-foundation/InfrastructureCore/Persistence/RepositoryBase.cs b/backend-foundation/InfrastructureCore/Persistence/RepositoryBase.cs new file mode 100644 index 000000000..87abec8cc --- /dev/null +++ b/backend-foundation/InfrastructureCore/Persistence/RepositoryBase.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Persistence; + +namespace PlatformPlatform.Foundation.InfrastructureCore.Persistence; + +public abstract class RepositoryBase : IRepository + where T : AggregateRoot + where TId : IComparable +{ + protected readonly DbSet DbSet; + + protected RepositoryBase(DbContext context) + { + DbSet = context.Set(); + } + + public async Task GetByIdAsync(TId id, CancellationToken cancellationToken) + { + return await DbSet.FindAsync(new object?[] {id}, cancellationToken); + } + + public void Add(T aggregate) + { + DbSet.Add(aggregate); + } + + public void Update(T aggregate) + { + DbSet.Update(aggregate); + } + + public void Remove(T aggregate) + { + DbSet.Remove(aggregate); + } +} \ No newline at end of file diff --git a/account-management/src/Foundation/Infrastructure/UnitOfWork.cs b/backend-foundation/InfrastructureCore/Persistence/UnitOfWork.cs similarity index 82% rename from account-management/src/Foundation/Infrastructure/UnitOfWork.cs rename to backend-foundation/InfrastructureCore/Persistence/UnitOfWork.cs index fef0c6131..115aaf34d 100644 --- a/account-management/src/Foundation/Infrastructure/UnitOfWork.cs +++ b/backend-foundation/InfrastructureCore/Persistence/UnitOfWork.cs @@ -1,9 +1,10 @@ using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Application.Persistence; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Behaviors; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Persistence; -namespace PlatformPlatform.Foundation.Infrastructure; +namespace PlatformPlatform.Foundation.InfrastructureCore.Persistence; /// /// UnitOfWork is an implementation of the IUnitOfWork interface from the Domain layer. It is responsible for diff --git a/account-management/src/Foundation/DependencyInjection.cs b/backend-foundation/InfrastructureCore/PersistenceInfrastructureConfiguration.cs similarity index 58% rename from account-management/src/Foundation/DependencyInjection.cs rename to backend-foundation/InfrastructureCore/PersistenceInfrastructureConfiguration.cs index bfe3e7c15..064f49b53 100644 --- a/account-management/src/Foundation/DependencyInjection.cs +++ b/backend-foundation/InfrastructureCore/PersistenceInfrastructureConfiguration.cs @@ -1,26 +1,17 @@ using System.Reflection; -using MediatR; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using PlatformPlatform.Foundation.Application.DomainEvents; -using PlatformPlatform.Foundation.Application.Persistence; -using PlatformPlatform.Foundation.Domain; -using PlatformPlatform.Foundation.Infrastructure; +using PlatformPlatform.Foundation.DomainModeling.Persistence; +using PlatformPlatform.Foundation.InfrastructureCore.Persistence; -namespace PlatformPlatform.Foundation; +namespace PlatformPlatform.Foundation.InfrastructureCore; -public static class DependencyInjection +public static class PersistenceInfrastructureConfiguration { - public static IServiceCollection AddFoundationServices(this IServiceCollection services) - { - services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnitOfWorkPipelineBehavior<,>)); - services.AddTransient(typeof(IPipelineBehavior<,>), typeof(PublishDomainEventsPipelineBehavior<,>)); - - return services; - } - - public static void ConfigureDatabaseContext(this IServiceCollection services, IConfiguration configuration) + public static IServiceCollection ConfigureDatabaseContext(this IServiceCollection services, + IConfiguration configuration) where T : DbContext { services.AddDbContext((_, optionsBuilder) => @@ -35,9 +26,12 @@ public static void ConfigureDatabaseContext(this IServiceCollection services, }); services.AddScoped(provider => new UnitOfWork(provider.GetRequiredService())); + + return services; } - public static void RegisterRepositories(this IServiceCollection services, Assembly assembly) + [UsedImplicitly] + public static IServiceCollection RegisterRepositories(this IServiceCollection services, Assembly assembly) { // Scrutor will scan the assembly for all classes that implement the IRepository // and register them as a service in the container. @@ -46,5 +40,7 @@ public static void RegisterRepositories(this IServiceCollection services, Assemb .AddClasses() .AsImplementedInterfaces() .WithScopedLifetime()); + + return services; } } \ No newline at end of file diff --git a/account-management/tests/Foundation.Tests/Application/DomainEvents/PublishDomainEventsPipelineBehaviorTests.cs b/backend-foundation/Tests/DomainModeling/Behaviors/PublishDomainEventsPipelineBehaviorTests.cs similarity index 86% rename from account-management/tests/Foundation.Tests/Application/DomainEvents/PublishDomainEventsPipelineBehaviorTests.cs rename to backend-foundation/Tests/DomainModeling/Behaviors/PublishDomainEventsPipelineBehaviorTests.cs index 2db061c1f..5a259e12c 100644 --- a/account-management/tests/Foundation.Tests/Application/DomainEvents/PublishDomainEventsPipelineBehaviorTests.cs +++ b/backend-foundation/Tests/DomainModeling/Behaviors/PublishDomainEventsPipelineBehaviorTests.cs @@ -1,12 +1,12 @@ using FluentAssertions; using MediatR; using NSubstitute; -using PlatformPlatform.Foundation.Application.DomainEvents; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Behaviors; +using PlatformPlatform.Foundation.DomainModeling.Persistence; using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Application.DomainEvents; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.Behaviors; public class PublishDomainEventsPipelineBehaviorTests { diff --git a/account-management/tests/Foundation.Tests/Application/Persistence/UnitOfWorkPipelineBehaviorTests.cs b/backend-foundation/Tests/DomainModeling/Behaviors/UnitOfWorkPipelineBehaviorTests.cs similarity index 82% rename from account-management/tests/Foundation.Tests/Application/Persistence/UnitOfWorkPipelineBehaviorTests.cs rename to backend-foundation/Tests/DomainModeling/Behaviors/UnitOfWorkPipelineBehaviorTests.cs index 3ca33f203..817a46192 100644 --- a/account-management/tests/Foundation.Tests/Application/Persistence/UnitOfWorkPipelineBehaviorTests.cs +++ b/backend-foundation/Tests/DomainModeling/Behaviors/UnitOfWorkPipelineBehaviorTests.cs @@ -1,11 +1,11 @@ using MediatR; using NSubstitute; -using PlatformPlatform.Foundation.Application.Persistence; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Behaviors; +using PlatformPlatform.Foundation.DomainModeling.Persistence; using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Application.Persistence; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.Behaviors; public class UnitOfWorkPipelineBehaviorTests { diff --git a/account-management/tests/Foundation.Tests/Domain/DomainEventTests.cs b/backend-foundation/Tests/DomainModeling/DomainEvents/DomainEventTests.cs similarity index 88% rename from account-management/tests/Foundation.Tests/Domain/DomainEventTests.cs rename to backend-foundation/Tests/DomainModeling/DomainEvents/DomainEventTests.cs index eb0f308e6..de8a1dc21 100644 --- a/account-management/tests/Foundation.Tests/Domain/DomainEventTests.cs +++ b/backend-foundation/Tests/DomainModeling/DomainEvents/DomainEventTests.cs @@ -2,7 +2,7 @@ using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Domain; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.DomainEvents; public class DomainEventTests { diff --git a/account-management/tests/Foundation.Tests/Domain/EntityEqualityComparerTests.cs b/backend-foundation/Tests/DomainModeling/Entities/EntityEqualityComparerTests.cs similarity index 94% rename from account-management/tests/Foundation.Tests/Domain/EntityEqualityComparerTests.cs rename to backend-foundation/Tests/DomainModeling/Entities/EntityEqualityComparerTests.cs index a0d3a7cd1..8a650bf91 100644 --- a/account-management/tests/Foundation.Tests/Domain/EntityEqualityComparerTests.cs +++ b/backend-foundation/Tests/DomainModeling/Entities/EntityEqualityComparerTests.cs @@ -1,8 +1,8 @@ using FluentAssertions; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Domain; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.Entities; public class EntityEqualityComparerTests { diff --git a/account-management/tests/Foundation.Tests/Domain/EntityTests.cs b/backend-foundation/Tests/DomainModeling/Entities/EntityTests.cs similarity index 96% rename from account-management/tests/Foundation.Tests/Domain/EntityTests.cs rename to backend-foundation/Tests/DomainModeling/Entities/EntityTests.cs index 4e12611fd..c5635e9e6 100644 --- a/account-management/tests/Foundation.Tests/Domain/EntityTests.cs +++ b/backend-foundation/Tests/DomainModeling/Entities/EntityTests.cs @@ -1,9 +1,10 @@ using FluentAssertions; using JetBrains.Annotations; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Identity; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Domain; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.Entities; public static class EntityTests { diff --git a/account-management/tests/Foundation.Tests/Domain/IdGeneratorTests.cs b/backend-foundation/Tests/DomainModeling/Identity/IdGeneratorTests.cs similarity index 86% rename from account-management/tests/Foundation.Tests/Domain/IdGeneratorTests.cs rename to backend-foundation/Tests/DomainModeling/Identity/IdGeneratorTests.cs index 36508e1ab..d2bcc3c95 100644 --- a/account-management/tests/Foundation.Tests/Domain/IdGeneratorTests.cs +++ b/backend-foundation/Tests/DomainModeling/Identity/IdGeneratorTests.cs @@ -1,8 +1,8 @@ using FluentAssertions; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Identity; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Domain; +namespace PlatformPlatform.Foundation.Tests.DomainModeling.Identity; public class IdGeneratorTests { diff --git a/account-management/tests/Foundation.Tests/Infrastructure/SaveChangesInterceptorTests.cs b/backend-foundation/Tests/InfrastructureCore/EntityFramework/SaveChangesInterceptorTests.cs similarity index 95% rename from account-management/tests/Foundation.Tests/Infrastructure/SaveChangesInterceptorTests.cs rename to backend-foundation/Tests/InfrastructureCore/EntityFramework/SaveChangesInterceptorTests.cs index db5791675..fceb90a2b 100644 --- a/account-management/tests/Foundation.Tests/Infrastructure/SaveChangesInterceptorTests.cs +++ b/backend-foundation/Tests/InfrastructureCore/EntityFramework/SaveChangesInterceptorTests.cs @@ -2,7 +2,7 @@ using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Infrastructure; +namespace PlatformPlatform.Foundation.Tests.InfrastructureCore.EntityFramework; public sealed class SaveChangesInterceptorTests : IDisposable { diff --git a/account-management/tests/Foundation.Tests/Infrastructure/RepositoryTests.cs b/backend-foundation/Tests/InfrastructureCore/Persistence/RepositoryTests.cs similarity index 97% rename from account-management/tests/Foundation.Tests/Infrastructure/RepositoryTests.cs rename to backend-foundation/Tests/InfrastructureCore/Persistence/RepositoryTests.cs index 051f3070d..5e310e16a 100644 --- a/account-management/tests/Foundation.Tests/Infrastructure/RepositoryTests.cs +++ b/backend-foundation/Tests/InfrastructureCore/Persistence/RepositoryTests.cs @@ -1,10 +1,10 @@ using FluentAssertions; using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Identity; using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Infrastructure; +namespace PlatformPlatform.Foundation.Tests.InfrastructureCore.Persistence; public sealed class RepositoryTests : IDisposable { diff --git a/account-management/tests/Foundation.Tests/Infrastructure/UnitOfWorkTests.cs b/backend-foundation/Tests/InfrastructureCore/Persistence/UnitOfWorkTests.cs similarity index 94% rename from account-management/tests/Foundation.Tests/Infrastructure/UnitOfWorkTests.cs rename to backend-foundation/Tests/InfrastructureCore/Persistence/UnitOfWorkTests.cs index 6d53cbcbc..921023fb5 100644 --- a/account-management/tests/Foundation.Tests/Infrastructure/UnitOfWorkTests.cs +++ b/backend-foundation/Tests/InfrastructureCore/Persistence/UnitOfWorkTests.cs @@ -1,11 +1,11 @@ using FluentAssertions; using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Domain; -using PlatformPlatform.Foundation.Infrastructure; +using PlatformPlatform.Foundation.DomainModeling.Persistence; +using PlatformPlatform.Foundation.InfrastructureCore.Persistence; using PlatformPlatform.Foundation.Tests.TestEntities; using Xunit; -namespace PlatformPlatform.Foundation.Tests.Infrastructure; +namespace PlatformPlatform.Foundation.Tests.InfrastructureCore.Persistence; public sealed class UnitOfWorkTests : IDisposable { diff --git a/backend-foundation/Tests/TestEntities/ITestAggregateRepository.cs b/backend-foundation/Tests/TestEntities/ITestAggregateRepository.cs new file mode 100644 index 000000000..f7eeb4769 --- /dev/null +++ b/backend-foundation/Tests/TestEntities/ITestAggregateRepository.cs @@ -0,0 +1,7 @@ +using PlatformPlatform.Foundation.DomainModeling.Persistence; + +namespace PlatformPlatform.Foundation.Tests.TestEntities; + +public interface ITestAggregateRepository : IRepository +{ +} \ No newline at end of file diff --git a/account-management/tests/Foundation.Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs b/backend-foundation/Tests/TestEntities/SqliteInMemoryDbContextFactory.cs similarity index 93% rename from account-management/tests/Foundation.Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs rename to backend-foundation/Tests/TestEntities/SqliteInMemoryDbContextFactory.cs index b93b65acb..f4f8c37cd 100644 --- a/account-management/tests/Foundation.Tests/Infrastructure/SqliteInMemoryDbContextFactory.cs +++ b/backend-foundation/Tests/TestEntities/SqliteInMemoryDbContextFactory.cs @@ -1,7 +1,7 @@ using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; -namespace PlatformPlatform.Foundation.Tests.Infrastructure; +namespace PlatformPlatform.Foundation.Tests.TestEntities; public sealed class SqliteInMemoryDbContextFactory : IDisposable where T : DbContext { diff --git a/account-management/tests/Foundation.Tests/TestEntities/TestAggregate.cs b/backend-foundation/Tests/TestEntities/TestAggregate.cs similarity index 84% rename from account-management/tests/Foundation.Tests/TestEntities/TestAggregate.cs rename to backend-foundation/Tests/TestEntities/TestAggregate.cs index 589005b84..63c0ce09b 100644 --- a/account-management/tests/Foundation.Tests/TestEntities/TestAggregate.cs +++ b/backend-foundation/Tests/TestEntities/TestAggregate.cs @@ -1,5 +1,6 @@ using JetBrains.Annotations; -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.Entities; +using PlatformPlatform.Foundation.DomainModeling.Identity; namespace PlatformPlatform.Foundation.Tests.TestEntities; diff --git a/account-management/tests/Foundation.Tests/TestEntities/TestAggregateCreatedEvent.cs b/backend-foundation/Tests/TestEntities/TestAggregateCreatedEvent.cs similarity index 58% rename from account-management/tests/Foundation.Tests/TestEntities/TestAggregateCreatedEvent.cs rename to backend-foundation/Tests/TestEntities/TestAggregateCreatedEvent.cs index 03cd27b70..510984b9a 100644 --- a/account-management/tests/Foundation.Tests/TestEntities/TestAggregateCreatedEvent.cs +++ b/backend-foundation/Tests/TestEntities/TestAggregateCreatedEvent.cs @@ -1,4 +1,4 @@ -using PlatformPlatform.Foundation.Domain; +using PlatformPlatform.Foundation.DomainModeling.DomainEvents; namespace PlatformPlatform.Foundation.Tests.TestEntities; diff --git a/backend-foundation/Tests/TestEntities/TestAggregateRepository.cs b/backend-foundation/Tests/TestEntities/TestAggregateRepository.cs new file mode 100644 index 000000000..c9e1e3d15 --- /dev/null +++ b/backend-foundation/Tests/TestEntities/TestAggregateRepository.cs @@ -0,0 +1,11 @@ +using PlatformPlatform.Foundation.InfrastructureCore.Persistence; + +namespace PlatformPlatform.Foundation.Tests.TestEntities; + +public class TestAggregateRepository : RepositoryBase, ITestAggregateRepository +{ + // ReSharper disable once SuggestBaseTypeForParameterInConstructor + public TestAggregateRepository(TestDbContext testDbContext) : base(testDbContext) + { + } +} \ No newline at end of file diff --git a/account-management/tests/Foundation.Tests/TestEntities/TestCommand.cs b/backend-foundation/Tests/TestEntities/TestCommand.cs similarity index 100% rename from account-management/tests/Foundation.Tests/TestEntities/TestCommand.cs rename to backend-foundation/Tests/TestEntities/TestCommand.cs diff --git a/account-management/tests/Foundation.Tests/TestEntities/TestDbContext.cs b/backend-foundation/Tests/TestEntities/TestDbContext.cs similarity index 87% rename from account-management/tests/Foundation.Tests/TestEntities/TestDbContext.cs rename to backend-foundation/Tests/TestEntities/TestDbContext.cs index f5d3fa5c4..720fc326c 100644 --- a/account-management/tests/Foundation.Tests/TestEntities/TestDbContext.cs +++ b/backend-foundation/Tests/TestEntities/TestDbContext.cs @@ -1,5 +1,5 @@ using Microsoft.EntityFrameworkCore; -using PlatformPlatform.Foundation.Infrastructure; +using PlatformPlatform.Foundation.InfrastructureCore.EntityFramework; namespace PlatformPlatform.Foundation.Tests.TestEntities; diff --git a/account-management/tests/Foundation.Tests/Foundation.Tests.csproj b/backend-foundation/Tests/Tests.csproj similarity index 86% rename from account-management/tests/Foundation.Tests/Foundation.Tests.csproj rename to backend-foundation/Tests/Tests.csproj index e9bc0612f..ffde3b1ac 100644 --- a/account-management/tests/Foundation.Tests/Foundation.Tests.csproj +++ b/backend-foundation/Tests/Tests.csproj @@ -11,14 +11,9 @@ true - - - - - @@ -34,4 +29,10 @@ + + + + + + diff --git a/account-management/global.json b/global.json similarity index 100% rename from account-management/global.json rename to global.json