Files
Nemera/src/Lumina.Application/Common/DependencyInjection/ApplicationLayerServices.cs
T
BinaryAlley 433f0c2ad5 Adds strongly typed IOptions<T> binding, with Fluent Validation and shared appsettings
- Adds strongly typed binding for IOptions<T> to map configuration sections from appsettings.json.
- Integrates FluentValidation for validating bound properties.
- Introduces appsettings.shared.json for shared configurations across applications.
Updates application-specific appsettings.json to focus on individual settings.
2024-08-25 16:59:19 +03:00

46 lines
1.8 KiB
C#

#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;
/// <summary>
/// Contains all services of the Application layer.
/// </summary>
public static class ApplicationLayerServices
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Registers the services of the Application layer into the dependency injection container.
/// </summary>
/// <param name="services">The service collection to add the services to.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
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<IMapper, ServiceMapper>();
return services;
}
#endregion
}