#region ========================================================================= USING ===================================================================================== using Lumina.Application.Common.Behaviors; using Mediator; using Microsoft.Extensions.DependencyInjection; using FluentValidation; using MapsterMapper; using Mapster; #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 updated . 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); // register mapster configs in this assembly var mapsterConfig = TypeAdapterConfig.GlobalSettings; mapsterConfig.Scan(typeof(ApplicationLayerServices).Assembly); services.AddSingleton(mapsterConfig); services.AddScoped(); return services; } #endregion }