30 lines
1.0 KiB
C#
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;
|
|
}
|
|
} |