using FluentValidation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using PARR.Core.Common.Implementations;
using PARR.Core.Common.Interfaces;
using PARR.Core.Services.Task.Implementations;
using PARR.Core.Services.Task.Interfaces;
using PARR.Domain.Settings;
namespace PARR.Core
{
public static class DependencyInjection
{
///
/// Регистрация Core (BLL) сервисов
///
///
///
///
public static IServiceCollection AddCoreServices(this IServiceCollection services, IConfiguration configuration)
{
// Регим профили AutoMapper
services.AddBllMapping();
// Регим все валидаторы в Core
services.AddValidatorsFromAssembly(typeof(DependencyInjection).Assembly, includeInternalTypes: true);
// Регим настройки
services.RegisterSettings(configuration);
// --- Регистрируем сревисы Core ---
#region Common
services.AddTransient();
#endregion
#region Services
services.AddScoped();
//services.AddScoped();
#endregion
return services;
}
private static IServiceCollection AddBllMapping(this IServiceCollection services)
{
// AutoMapper
services.AddAutoMapper(cfg =>
{
// регим все в Core
cfg.AddMaps(typeof(DependencyInjection).Assembly);
});
return services;
}
///
/// Регистрация настроек
///
///
///
///
private static IServiceCollection RegisterSettings(this IServiceCollection services, IConfiguration configuration)
{
var groupedShortcodesCacheSettings = new GroupedShortcodesCacheSettings();
configuration.GetSection(nameof(GroupedShortcodesCacheSettings)).Bind(groupedShortcodesCacheSettings);
services.AddSingleton(groupedShortcodesCacheSettings);
return services;
}
}
}