Adds dependency injection services of the Application layer

This commit is contained in:
BinaryAlley committed 2024-08-23 19:45:51 +03:00
1 parent 5dc40db307
commit c2676cdb1d
1 file changed
+38
@@ -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;
/// <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 service collection with the added services.</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);
return services;
}
#endregion
}