Update
This commit is contained in:
32
src/BackOffice.BFF.Application/ConfigureServices.cs
Normal file
32
src/BackOffice.BFF.Application/ConfigureServices.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using BackOffice.BFF.Application.Common.Behaviours;
|
||||
using MapsterMapper;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
public static class ConfigureServices
|
||||
{
|
||||
public static IServiceCollection AddApplicationServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddMapping();
|
||||
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
|
||||
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
|
||||
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(PerformanceBehaviour<,>));
|
||||
|
||||
return services;
|
||||
}
|
||||
private static IServiceCollection AddMapping(this IServiceCollection services)
|
||||
{
|
||||
var typeAdapterConfig = TypeAdapterConfig.GlobalSettings;
|
||||
// scans the assembly and gets the IRegister, adding the registration to the TypeAdapterConfig
|
||||
typeAdapterConfig.Scan(Assembly.GetExecutingAssembly());
|
||||
// register the mapper as Singleton service for my application
|
||||
var mapperConfig = new Mapper(typeAdapterConfig);
|
||||
services.AddSingleton<IMapper>(mapperConfig);
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user