remove CacheDb from ConsoleApp1

This commit is contained in:
ngfrolov 2022-11-18 15:49:04 +05:00
parent b2844cd5b2
commit 342f5845f4

View File

@ -1,9 +1,9 @@
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services; using AsbCloudInfrastructure.Services;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.Services.SAUB; using AsbCloudInfrastructure.Services.SAUB;
using AsbCloudInfrastructure.Services.WellOperationService; using AsbCloudInfrastructure.Services.WellOperationService;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives; using Microsoft.Extensions.Primitives;
using System.Collections.Generic; using System.Collections.Generic;
@ -41,19 +41,20 @@ namespace ConsoleApp1
internal static class ServiceFactory internal static class ServiceFactory
{ {
private static DbContextOptions<AsbCloudDbContext> options = new DbContextOptionsBuilder<AsbCloudDbContext>() private static readonly DbContextOptions<AsbCloudDbContext> options = new DbContextOptionsBuilder<AsbCloudDbContext>()
.UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") .UseNpgsql("Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True")
.Options; .Options;
static CacheDb CacheDb { get; } = new CacheDb();
static ConfigurationService ConfigurationService { get; } = new ConfigurationService(); static ConfigurationService ConfigurationService { get; } = new ConfigurationService();
static TimezoneService TimezoneService { get; } = new TimezoneService(); static TimezoneService TimezoneService { get; } = new TimezoneService();
public static AsbCloudDbContext Context { get; } = MakeContext(); public static AsbCloudDbContext Context { get; } = MakeContext();
public static AsbCloudDbContext MakeContext() public static AsbCloudDbContext MakeContext()
=> MakeContext(options); => MakeContext(options);
public static IMemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions());
public static AsbCloudDbContext MakeContext(DbContextOptions<AsbCloudDbContext> options) public static AsbCloudDbContext MakeContext(DbContextOptions<AsbCloudDbContext> options)
=> new AsbCloudDbContext(options); => new (options);
public static AsbCloudDbContext MakeContext(string cusomConnectionString) public static AsbCloudDbContext MakeContext(string cusomConnectionString)
=> MakeContext(new DbContextOptionsBuilder<AsbCloudDbContext>().UseNpgsql(cusomConnectionString).Options); => MakeContext(new DbContextOptionsBuilder<AsbCloudDbContext>().UseNpgsql(cusomConnectionString).Options);
@ -62,21 +63,21 @@ namespace ConsoleApp1
=> AsbCloudInfrastructure.DependencyInjection.MapsterSetup(); => AsbCloudInfrastructure.DependencyInjection.MapsterSetup();
public static TelemetryTracker MakeTelemetryTracker() public static TelemetryTracker MakeTelemetryTracker()
=> new TelemetryTracker(CacheDb, ConfigurationService); => new (ConfigurationService, memoryCache);
public static TelemetryService MakeTelemetryService() public static TelemetryService MakeTelemetryService()
=> new TelemetryService(Context, MakeTelemetryTracker(), TimezoneService); => new (Context, MakeTelemetryTracker(), TimezoneService);
public static WellService MakeWellService() public static WellService MakeWellService()
=> new WellService(Context, CacheDb, MakeTelemetryService(), TimezoneService); => new (Context, memoryCache, MakeTelemetryService(), TimezoneService);
public static WellOperationService MakeWellOperationsService() public static WellOperationService MakeWellOperationsService()
=> new WellOperationService(Context, CacheDb, MakeWellService()); => new (Context, memoryCache, MakeWellService());
public static OperationsStatService MakeOperationsStatService() public static OperationsStatService MakeOperationsStatService()
=> new OperationsStatService(Context, CacheDb, MakeWellService()); => new (Context, memoryCache, MakeWellService());
public static ScheduleReportService MakeScheduleReportService() public static ScheduleReportService MakeScheduleReportService()
=> new ScheduleReportService(MakeOperationsStatService(), MakeWellService()); => new(MakeOperationsStatService(), MakeWellService());
} }
} }