diff --git a/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs new file mode 100644 index 00000000..221b509d --- /dev/null +++ b/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs @@ -0,0 +1,38 @@ +#region ========================================================================= USING ===================================================================================== +using Lumina.Application.Common.Behaviors; +using Mediator; +using Microsoft.Extensions.DependencyInjection; +using FluentValidation; +#endregion + +namespace Lumina.Application.Common.DependencyInjection; + +/// +/// Contains all services of the Application layer. +/// +public static class ApplicationLayerServices +{ + #region ===================================================================== METHODS =================================================================================== + /// + /// Registers the services of the Application layer into the dependency injection container. + /// + /// The service collection to add the services to. + /// The service collection with the added services. + public static IServiceCollection AddApplicationLayerServices(this IServiceCollection services) + { + // register Mediator + services.AddMediator(options => + { + options.ServiceLifetime = ServiceLifetime.Scoped; + }); + + // register the validation behavior + services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); + + // register fluent validators + services.AddValidatorsFromAssembly(typeof(ApplicationLayerServices).Assembly); + + return services; + } + #endregion +} \ No newline at end of file