DD.WellWorkover.Cloud/ConsoleApp1/ServiceFactory.cs

84 lines
3.1 KiB
C#
Raw Normal View History

2022-04-12 10:01:56 +05:00
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.WellOperationService;
using Microsoft.EntityFrameworkCore;
2022-11-18 15:49:04 +05:00
using Microsoft.Extensions.Caching.Memory;
2022-04-12 10:01:56 +05:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System.Collections.Generic;
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<IConfigurationSection> GetChildren()
{
return null;
}
public IChangeToken GetReloadToken()
{
return null;
}
public IConfigurationSection GetSection(string key) => this;
}
internal static class ServiceFactory
{
2022-11-18 15:49:04 +05:00
private static readonly DbContextOptions<AsbCloudDbContext> options = new DbContextOptionsBuilder<AsbCloudDbContext>()
2022-04-12 10:01:56 +05:00
.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()
2022-04-22 17:17:38 +05:00
=> MakeContext(options);
2022-11-18 15:49:04 +05:00
public static IMemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions());
2022-04-22 17:17:38 +05:00
public static AsbCloudDbContext MakeContext(DbContextOptions<AsbCloudDbContext> options)
2022-11-18 15:49:04 +05:00
=> new (options);
2022-04-12 10:01:56 +05:00
2022-04-22 17:17:38 +05:00
public static AsbCloudDbContext MakeContext(string cusomConnectionString)
=> MakeContext(new DbContextOptionsBuilder<AsbCloudDbContext>().UseNpgsql(cusomConnectionString).Options);
2022-04-12 10:01:56 +05:00
public static void MapsterSetup()
=> AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
public static TelemetryTracker MakeTelemetryTracker()
2022-11-18 15:49:04 +05:00
=> new (ConfigurationService, memoryCache);
2022-04-12 10:01:56 +05:00
2022-06-15 14:57:37 +05:00
public static TelemetryService MakeTelemetryService()
2022-11-18 15:49:04 +05:00
=> new (Context, MakeTelemetryTracker(), TimezoneService);
2022-04-12 10:01:56 +05:00
2022-06-15 14:57:37 +05:00
public static WellService MakeWellService()
2022-11-18 15:49:04 +05:00
=> new (Context, memoryCache, MakeTelemetryService(), TimezoneService);
2022-04-12 10:01:56 +05:00
2022-05-06 16:35:16 +05:00
public static WellOperationService MakeWellOperationsService()
2022-11-18 15:49:04 +05:00
=> new (Context, memoryCache, MakeWellService());
2022-05-06 16:35:16 +05:00
2022-04-12 10:01:56 +05:00
public static OperationsStatService MakeOperationsStatService()
2022-11-18 15:49:04 +05:00
=> new (Context, memoryCache, MakeWellService());
2022-04-12 10:01:56 +05:00
2022-06-15 14:57:37 +05:00
public static ScheduleReportService MakeScheduleReportService()
2022-11-18 15:49:04 +05:00
=> new(MakeOperationsStatService(), MakeWellService());
2022-04-12 10:01:56 +05:00
}
}