Skip to content

Commit

Permalink
[BDB-6] Combine DefaultModuleExtensions.cs with DefaultExtensions.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
phamhongphuc1403 committed Aug 11, 2024
1 parent 7c135ec commit c0f7a8f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
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;

namespace BuildingBlock.Presentation.API.Extensions;

public static class DefaultExtensions
{
public static IServiceCollection AddDefaultExtensions(this IServiceCollection services,
IConfiguration configuration)
public static async Task<IServiceCollection> AddDefaultExtensions<TApplicationAssemblyReference,
TDomainAssemblyReference, TDbContext>(this IServiceCollection services, IConfiguration configuration)
where TDbContext : BaseDbContext
where TApplicationAssemblyReference : ApplicationAssemblyReference
where TDomainAssemblyReference : DomainAssemblyReference
{
services
.AddControllers()
Expand All @@ -20,10 +27,25 @@ public static IServiceCollection AddDefaultExtensions(this IServiceCollection se
.AddApplicationCors(configuration)
.AddHttpContextAccessor()
.AddCurrentUser()
.AddDatabase<TDbContext>(configuration)
.AddMapper<TDbContext>()
.AddCqrs<TApplicationAssemblyReference, TDomainAssemblyReference>()
.AddDefaultOpenApi(configuration)
.AddEventBus(configuration)
.AddInMemoryCache(configuration)
.AddEmail(configuration);
.AddValidatorsFromAssembly(typeof(TApplicationAssemblyReference).Assembly)
.AddInMemoryCache(configuration);

services
.RegisterSeeders<TApplicationAssemblyReference>()
.RegisterServices<TApplicationAssemblyReference>()
.RegisterServices<TDomainAssemblyReference>()
.RegisterDefaultRepositories<TDomainAssemblyReference, TDbContext>()
.RegisterCustomRepositories<TDbContext>()
.RegisterCachedRepositories<TDbContext>()
.RegisterIntegrationEventHandlers<TApplicationAssemblyReference>()
.RegisterUnitOfWork<TDbContext>();

await services.ApplyMigrationAsync<TDbContext>();

return services;
}
Expand Down

This file was deleted.

0 comments on commit c0f7a8f

Please sign in to comment.