Files
blazor-scm/ConfigBackEnd/DI.cs
T
2026-07-21 14:28:43 +07:00

30 lines
1.0 KiB
C#

namespace Indotalent.ConfigBackEnd;
using FluentValidation;
using Indotalent.ConfigBackEnd.Behaviours;
using MediatR;
using MediatR.Pipeline;
using Microsoft.Extensions.DependencyInjection;
public static class DI
{
public static IServiceCollection AddConfigBackEndDI(this IServiceCollection services)
{
services.AddMediatR(cfg =>
{
cfg.RegisterServicesFromAssembly(typeof(DI).Assembly);
cfg.AddRequestPreProcessor(typeof(IRequestPreProcessor<>), typeof(LoggingBehaviour<>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
cfg.Lifetime = ServiceLifetime.Scoped;
});
services.AddValidatorsFromAssembly(typeof(DI).Assembly);
return services;
}
}