using API.Errors; using Core.Interfaces; using Infrastructure.Data; using Infrastructure.Services; using Microsoft.AspNetCore.Mvc; namespace API.Extensions { public static class ApplicationServicesExtensions { public static IServiceCollection AddApplicationServices(this IServiceCollection services) { services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(typeof(IGenericRepository<>), (typeof(GenericRepository<>))); services.Configure(options => options.InvalidModelStateResponseFactory = actionContext => { var errors = actionContext.ModelState .Where(e => e.Value.Errors.Count > 0) .SelectMany(x => x.Value.Errors) .Select(x => x.ErrorMessage).ToArray(); var errorRepsponse = new ApiValidationErrorResponse { Errors = errors }; return new BadRequestObjectResult(errorRepsponse); }); return services; } } }