From c0f7a8f0f46e14e2d70d180b33e438057c32a1d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ph=C3=BAc=20Ph=E1=BA=A1m=20H=E1=BB=93ng?= Date: Sun, 11 Aug 2024 18:35:34 +0700 Subject: [PATCH] [BDB-6] Combine DefaultModuleExtensions.cs with DefaultExtensions.cs --- .../Extensions/DefaultExtensions.cs | 30 ++++++++++++-- .../Extensions/ModuleExtension.cs | 39 ------------------- 2 files changed, 26 insertions(+), 43 deletions(-) delete mode 100644 Presentations/BuildingBlock.Presentation.API/Extensions/ModuleExtension.cs diff --git a/Presentations/BuildingBlock.Presentation.API/Extensions/DefaultExtensions.cs b/Presentations/BuildingBlock.Presentation.API/Extensions/DefaultExtensions.cs index a224909..907e10a 100644 --- a/Presentations/BuildingBlock.Presentation.API/Extensions/DefaultExtensions.cs +++ b/Presentations/BuildingBlock.Presentation.API/Extensions/DefaultExtensions.cs @@ -1,4 +1,8 @@ using System.Text.Json.Serialization; +using BuildingBlock.Core.Application; +using BuildingBlock.Core.Domain; +using BuildingBlock.Infrastructure.EntityFrameworkCore; +using FluentValidation; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; @@ -6,8 +10,11 @@ namespace BuildingBlock.Presentation.API.Extensions; public static class DefaultExtensions { - public static IServiceCollection AddDefaultExtensions(this IServiceCollection services, - IConfiguration configuration) + public static async Task AddDefaultExtensions(this IServiceCollection services, IConfiguration configuration) + where TDbContext : BaseDbContext + where TApplicationAssemblyReference : ApplicationAssemblyReference + where TDomainAssemblyReference : DomainAssemblyReference { services .AddControllers() @@ -20,10 +27,25 @@ public static IServiceCollection AddDefaultExtensions(this IServiceCollection se .AddApplicationCors(configuration) .AddHttpContextAccessor() .AddCurrentUser() + .AddDatabase(configuration) + .AddMapper() + .AddCqrs() .AddDefaultOpenApi(configuration) .AddEventBus(configuration) - .AddInMemoryCache(configuration) - .AddEmail(configuration); + .AddValidatorsFromAssembly(typeof(TApplicationAssemblyReference).Assembly) + .AddInMemoryCache(configuration); + + services + .RegisterSeeders() + .RegisterServices() + .RegisterServices() + .RegisterDefaultRepositories() + .RegisterCustomRepositories() + .RegisterCachedRepositories() + .RegisterIntegrationEventHandlers() + .RegisterUnitOfWork(); + + await services.ApplyMigrationAsync(); return services; } diff --git a/Presentations/BuildingBlock.Presentation.API/Extensions/ModuleExtension.cs b/Presentations/BuildingBlock.Presentation.API/Extensions/ModuleExtension.cs deleted file mode 100644 index 0b1dc7f..0000000 --- a/Presentations/BuildingBlock.Presentation.API/Extensions/ModuleExtension.cs +++ /dev/null @@ -1,39 +0,0 @@ -using BuildingBlock.Core.Application; -using BuildingBlock.Core.Domain; -using FluentValidation; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; - -namespace BuildingBlock.Presentation.API.Extensions; - -public static class ModuleExtension -{ - public static async Task AddDefaultModuleExtensionsAsync(this IServiceCollection services, - IConfiguration configuration) where TDbContext : DbContext - where TApplicationAssemblyReference : ApplicationAssemblyReference - where TDomainAssemblyReference : DomainAssemblyReference - { - services - .AddDatabase(configuration) - .AddMapper() - .AddCqrs() - .AddValidatorsFromAssembly(typeof(TApplicationAssemblyReference).Assembly); - - services - .RegisterSeeders() - .RegisterServices() - .RegisterServices() - .RegisterDefaultRepositories() - .RegisterCustomRepositories() - .RegisterCachedRepositories() - .RegisterIntegrationEventHandlers() - .RegisterUnitOfWork(); - - await services.ApplyMigrationAsync(); - - return services; - } -} \ No newline at end of file