DD.WellWorkover.Cloud/AsbCloudInfrastructure/DependencyInjection.cs
2021-04-07 18:01:56 +05:00

40 lines
1.4 KiB
C#

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace AsbCloudInfrastructure
{
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
services.AddDbContext<AsbCloudDbContext>(options =>
options.UseNpgsql(configuration.GetConnectionString("DefaultConnection")));
services.AddScoped<IAsbCloudDbContext>(provider => provider.GetService<AsbCloudDbContext>());
services.AddSingleton(new MapperConfiguration(AutoMapperConfig));
services.AddSingleton(new CacheDb());
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IWellService, WellService>();
services.AddTransient<ITelemetryService, TelemetryService>();
services.AddTransient<ITelemetryDataService, TelemetryDataService>();
return services;
}
private static void AutoMapperConfig(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<DataSaubBase, DataSaubBaseDto>();
cfg.CreateMap<DataSaubBaseDto, DataSaubBase>();
}
}
}