DD.WellWorkover.Cloud/AsbCloudInfrastructure/DependencyInjection.cs

49 lines
1.9 KiB
C#
Raw Normal View History

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
2021-04-07 18:01:56 +05:00
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));
2021-04-07 18:01:56 +05:00
services.AddSingleton(new CacheDb());
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IWellService, WellService>();
2021-04-07 18:01:56 +05:00
services.AddTransient<ITelemetryService, TelemetryService>();
2021-04-23 10:21:25 +05:00
services.AddTransient<IDataService, DataService>();
services.AddTransient<IMessageService, MessageService>();
services.AddTransient<IEventService, EventService>();
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
return services;
}
private static void AutoMapperConfig(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<DataSaubBase, DataSaubBaseDto>();
2021-04-07 18:01:56 +05:00
cfg.CreateMap<DataSaubBaseDto, DataSaubBase>();
2021-04-23 10:21:25 +05:00
cfg.CreateMap<Message, TelemetryMessageDto>();
cfg.CreateMap<TelemetryMessageDto, Message>();
cfg.CreateMap<TelemetryInfo, TelemetryInfoDto>();
cfg.CreateMap<TelemetryInfoDto, TelemetryInfo>();
}
}
}