using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.Analysis; using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services.WellOperationService; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; namespace AsbCloudInfrastructure { public static class DependencyInjection { public static IAsbCloudDbContext MakeContext(string connectionString) { var options = new DbContextOptionsBuilder() .UseNpgsql(connectionString) .Options; var context = new AsbCloudDbContext(options); return context; } public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration) { services.AddDbContext(options => options.UseNpgsql(configuration.GetConnectionString("DefaultConnection"))); services.AddScoped(provider => provider.GetService()); services.AddScoped(); services.AddHostedService(); services.AddHostedService(); services.AddSingleton(new CacheDb()); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); // admin crud services: services.AddTransient, CrudServiceBase>(); services.AddTransient, CrudServiceBase>(); services.AddTransient, CrudServiceBase>(); services.AddTransient, DrillParamsService>(); services.AddTransient, CrudServiceBase>(); services.AddTransient, CrudServiceBase>(); services.AddTransient, CrudServiceBase>(); // TelemetryData services services.AddTransient, TelemetryDataSaubService>(); services.AddTransient, TelemetryDataSpinService>(); return services; } public static IServiceCollection AddTransientLazy(this IServiceCollection services) where TService : class where TImplementation : class, TService => services.AddTransient() .AddTransient(provider => new Lazy(provider.GetService)); public static IServiceCollection AddTransientLazy(this IServiceCollection services, Func implementationFactory) where TService : class where TImplementation : class, TService => services.AddTransient(implementationFactory) .AddTransient(provider => new Lazy(() => implementationFactory(provider))); } }