Currently, I am working on a .NET Core 6.0 project that uses MediatR, Automapper, and FluentValidation.
I understand the FluentValidation validators are registered by using the "AddValidatorsFromAssembly" method like below
public static void AddApplicationLayer(this IServiceCollection services)
{
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
}
However, the project I am working on looks like this
protected internal override void AddServices(IServiceCollection services)
{
services.AddMediatR(typeof(Program));
services.Scan(s => s
.FromAssembliesOf(this.AssemblyMarkerTypes)
.AddClasses(false)
.UsingRegistrationStrategy(RegistrationStrategy.Append)
.AsImplementedInterfaces()
.WithTransientLifetime());
services.AddAutoMapper(typeof(Program));
services.AddControllers();
services.AddHealthChecks();
base.AddServices(services);
}
It is not clear to me how FluentValidation validators are registered without calling AddValidatorsFromAssembly.
Additionally, it is not clear what the following code does.
services.Scan(s => s
.FromAssembliesOf(this.AssemblyMarkerTypes)
.AddClasses(false)
.UsingRegistrationStrategy(RegistrationStrategy.Append)
.AsImplementedInterfaces()
.WithTransientLifetime());
If the above scan, register all the DIs, why do we need a separate registrations for AddAutoMapper & AddMediatR?