first commit

This commit is contained in:
2026-02-26 14:04:18 +07:00
parent 57ac80a666
commit 4b7236493f
92 changed files with 4999 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using FluentValidation;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using MyNewProjectName.Application.Behaviors;
namespace MyNewProjectName.Application;
/// <summary>
/// Dependency Injection for Application Layer
/// </summary>
public static class DependencyInjection
{
public static IServiceCollection AddApplication(this IServiceCollection services)
{
var assembly = Assembly.GetExecutingAssembly();
// Register AutoMapper
services.AddAutoMapper(assembly);
// Register MediatR
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(assembly);
// Logging phải đứng đầu tiên để ghi nhận request đến
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
// Sau đó mới đến Validation
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
});
// Register FluentValidation validators
services.AddValidatorsFromAssembly(assembly);
return services;
}
}