- Add MediatR 12.5.0, AutoMapper 13.0.1 packages - Create ValidationBehavior (FluentValidation pipeline) - Create LoggingBehavior (structured logging pipeline) - Create MappingProfile with IMapFrom<T> convention - Make ServiceResult properties public for pipeline use - Update Application DI with MediatR + AutoMapper registration
34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using System.Reflection;
|
|
using FluentValidation;
|
|
using Heimdall.Application.Behaviors;
|
|
using MediatR;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace Heimdall.Application;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddApplication(this IServiceCollection services)
|
|
{
|
|
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);
|
|
|
|
return services;
|
|
}
|
|
}
|