2026-07-22 19:31:51 +00:00
|
|
|
using System.Reflection;
|
2026-07-16 20:53:56 +00:00
|
|
|
using FluentValidation;
|
2026-07-22 19:31:51 +00:00
|
|
|
using Heimdall.Application.Behaviors;
|
|
|
|
|
using MediatR;
|
2026-07-16 20:53:56 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Application;
|
|
|
|
|
|
|
|
|
|
public static class DependencyInjection
|
|
|
|
|
{
|
|
|
|
|
public static IServiceCollection AddApplication(this IServiceCollection services)
|
|
|
|
|
{
|
2026-07-22 19:31:51 +00:00
|
|
|
var assembly = typeof(DependencyInjection).Assembly;
|
|
|
|
|
|
|
|
|
|
// MediatR — register all command/query handlers from this assembly
|
|
|
|
|
services.AddMediatR(cfg =>
|
|
|
|
|
{
|
|
|
|
|
cfg.RegisterServicesFromAssembly(assembly);
|
|
|
|
|
|
|
|
|
|
// Pipeline behaviors (executed in registration order)
|
|
|
|
|
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
|
|
|
|
|
cfg.AddBehavior(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// AutoMapper — scan assembly for profiles (including MappingProfile)
|
|
|
|
|
services.AddAutoMapper(assembly);
|
|
|
|
|
|
|
|
|
|
// FluentValidation — auto-register all validators
|
|
|
|
|
services.AddValidatorsFromAssembly(assembly);
|
2026-07-16 20:53:56 +00:00
|
|
|
|
|
|
|
|
return services;
|
|
|
|
|
}
|
|
|
|
|
}
|