first commit
This commit is contained in:
36
MyNewProjectName.Application/DependencyInjection.cs
Normal file
36
MyNewProjectName.Application/DependencyInjection.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user