using AsbCloudDb.Model; using AsbCloudInfrastructure.Repository; using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.WellOperationService; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Caching.Memory; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Primitives; using System.Collections.Generic; using System.Linq; namespace ConsoleApp1 { class ConfigurationService : IConfigurationSection { public string this[string key] { get => "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; set { } } public string Key => ""; public string Path => ""; public string Value { get; set; } = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True"; public IEnumerable GetChildren() { return Enumerable.Empty(); } public IChangeToken? GetReloadToken() { return default; } public IConfigurationSection GetSection(string key) => this; } internal static class ServiceFactory { private static readonly DbContextOptions options = new DbContextOptionsBuilder() .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") .Options; static ConfigurationService ConfigurationService { get; } = new ConfigurationService(); static TimezoneService TimezoneService { get; } = new TimezoneService(); public static AsbCloudDbContext Context { get; } = MakeContext(); public static AsbCloudDbContext MakeContext() => MakeContext(options); public static IMemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions()); public static AsbCloudDbContext MakeContext(DbContextOptions options) => new (options); public static AsbCloudDbContext MakeContext(string cusomConnectionString) => MakeContext(new DbContextOptionsBuilder().UseNpgsql(cusomConnectionString).Options); public static void MapsterSetup() => AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); public static TelemetryTracker MakeTelemetryTracker() => new (ConfigurationService, memoryCache); public static TelemetryService MakeTelemetryService() => new (Context, MakeTelemetryTracker(), TimezoneService); public static WellService MakeWellService() => new (Context, memoryCache, MakeTelemetryService(), TimezoneService); public static WellOperationRepository MakeWellOperationRepository() => new (Context, memoryCache, MakeWellService()); public static OperationsStatService MakeOperationsStatService() => new (Context, memoryCache, MakeWellService()); public static ScheduleReportService MakeScheduleReportService() => new(MakeOperationsStatService(), MakeWellService()); } }