DD.WellWorkover.Cloud/AsbCloudInfrastructure/DependencyInjection.cs

54 lines
2.1 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.AddHostedService<BackgroundWorkerService>();
services.AddSingleton(new MapperConfiguration(AutoMapperConfig));
services.AddSingleton(new CacheDb());
services.AddSingleton<ITelemetryTracker, TelemetryTracker>();
services.AddSingleton<IBackgroundQueue, BackgroundQueue>();
services.AddTransient<IAuthService, AuthService>();
services.AddTransient<IWellService, WellService>();
services.AddTransient<ITelemetryService, TelemetryService>();
services.AddTransient<IDataService, DataService>();
services.AddTransient<IMessageService, MessageService>();
services.AddTransient<IEventService, EventService>();
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
services.AddTransient<IReportService, ReportService>();
return services;
}
private static void AutoMapperConfig(IMapperConfigurationExpression cfg)
{
cfg.CreateMap<DataSaubBase, DataSaubBaseDto>();
cfg.CreateMap<DataSaubBaseDto, DataSaubBase>();
cfg.CreateMap<Message, TelemetryMessageDto>();
cfg.CreateMap<TelemetryMessageDto, Message>();
cfg.CreateMap<TelemetryInfo, TelemetryInfoDto>();
cfg.CreateMap<TelemetryInfoDto, TelemetryInfo>();
}
}
}