forked from ddrilling/AsbCloudServer
57 lines
2.4 KiB
C#
57 lines
2.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")), ServiceLifetime.Scoped);
|
|
|
|
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.AddSingleton<ISaubDataCache, SaubDataCache>();
|
|
|
|
services.AddTransient<IAuthService, AuthService>();
|
|
services.AddTransient<IWellService, WellService>();
|
|
services.AddTransient<IClusterService, ClusterService>();
|
|
services.AddTransient<ITelemetryService, TelemetryService>();
|
|
services.AddTransient<IDataService, DataService>();
|
|
services.AddTransient<IMessageService, MessageService>();
|
|
services.AddTransient<IEventService, EventService>();
|
|
services.AddTransient<ITelemetryUserService, TelemetryUserService>();
|
|
services.AddTransient<IReportService, ReportService>();
|
|
services.AddTransient<IAnalyticsService, AnalyticsService>();
|
|
|
|
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>();
|
|
}
|
|
}
|
|
}
|