From 4ec4ec17ebff6304e5fb03b54a5189d8c50e8bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8F=20=D0=91=D0=B8=D0=B7=D1=8E=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Fri, 27 Dec 2024 00:37:52 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=83=D1=88=20=D0=B8=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=B2=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=B5=20=D1=81=20=D0=B8=D0=BD=D1=82=D0=B5?= =?UTF-8?q?=D0=B3=D1=80=D0=B0=D1=86=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D0=BC?= =?UTF-8?q?=D0=B8=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DD.Persistence.API/DD.Persistence.API.csproj | 1 + .../Clients/DataSourceSystemClient.cs | 4 +-- .../Refit/IRefitDataSourceSystemClient.cs | 2 +- .../Interfaces/Refit/IRefitSetpointClient.cs | 2 +- .../Interfaces/Refit/IRefitWitsDataClient.cs | 2 +- .../Clients/SetpointClient.cs | 4 +-- DD.Persistence.Client/DependencyInjection.cs | 11 ++++---- .../PersistenceClientFactory.cs | 28 +++++++++---------- DD.Persistence.Client/RefitClientFactory.cs | 7 ++--- .../DataSourceSystemControllerTest.cs | 11 +++++--- .../Controllers/SetpointControllerTest.cs | 12 +++++--- .../Controllers/WitsDataControllerTest.cs | 12 +++++--- .../WebAppFactoryFixture.cs | 6 ++-- 13 files changed, 56 insertions(+), 46 deletions(-) diff --git a/DD.Persistence.API/DD.Persistence.API.csproj b/DD.Persistence.API/DD.Persistence.API.csproj index 5ed1097..e7d2e57 100644 --- a/DD.Persistence.API/DD.Persistence.API.csproj +++ b/DD.Persistence.API/DD.Persistence.API.csproj @@ -23,6 +23,7 @@ + diff --git a/DD.Persistence.Client/Clients/DataSourceSystemClient.cs b/DD.Persistence.Client/Clients/DataSourceSystemClient.cs index 45e2d29..7e70255 100644 --- a/DD.Persistence.Client/Clients/DataSourceSystemClient.cs +++ b/DD.Persistence.Client/Clients/DataSourceSystemClient.cs @@ -9,9 +9,9 @@ public class DataSourceSystemClient : BaseClient, IDataSourceSystemClient { private readonly IRefitDataSourceSystemClient dataSourceSystemClient; - public DataSourceSystemClient(IRefitDataSourceSystemClient dataSourceSystemClient, ILogger logger) : base(logger) + public DataSourceSystemClient(IRefitClientFactory dataSourceSystemClientFactory, ILogger logger) : base(logger) { - this.dataSourceSystemClient = dataSourceSystemClient; + this.dataSourceSystemClient = dataSourceSystemClientFactory.Create(); } public async Task Add(DataSourceSystemDto dataSourceSystemDto, CancellationToken token) diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs index a4b47eb..313d8cc 100644 --- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs +++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitDataSourceSystemClient.cs @@ -2,7 +2,7 @@ using Refit; namespace DD.Persistence.Client.Clients.Interfaces.Refit; -public interface IRefitDataSourceSystemClient : IDisposable +public interface IRefitDataSourceSystemClient : IRefitClient, IDisposable { private const string BaseRoute = "/api/dataSourceSystem"; diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs index b6e021a..1acb398 100644 --- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs +++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitSetpointClient.cs @@ -3,7 +3,7 @@ using Refit; namespace DD.Persistence.Client.Clients.Interfaces.Refit; -public interface IRefitSetpointClient : IDisposable +public interface IRefitSetpointClient : IRefitClient, IDisposable { private const string BaseRoute = "/api/setpoint"; diff --git a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs index 57bff6f..e7e6d9a 100644 --- a/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs +++ b/DD.Persistence.Client/Clients/Interfaces/Refit/IRefitWitsDataClient.cs @@ -3,7 +3,7 @@ using DD.Persistence.Models; using Refit; namespace DD.Persistence.Client.Clients.Interfaces.Refit; -public interface IRefitWitsDataClient : IDisposable +public interface IRefitWitsDataClient : IRefitClient, IDisposable { private const string BaseRoute = "/api/witsData"; diff --git a/DD.Persistence.Client/Clients/SetpointClient.cs b/DD.Persistence.Client/Clients/SetpointClient.cs index 4a990c5..808f0b9 100644 --- a/DD.Persistence.Client/Clients/SetpointClient.cs +++ b/DD.Persistence.Client/Clients/SetpointClient.cs @@ -10,9 +10,9 @@ public class SetpointClient : BaseClient, ISetpointClient { private readonly IRefitSetpointClient refitSetpointClient; - public SetpointClient(IRefitSetpointClient refitSetpointClient, ILogger logger) : base(logger) + public SetpointClient(IRefitClientFactory refitSetpointClientFactory, ILogger logger) : base(logger) { - this.refitSetpointClient = refitSetpointClient; + this.refitSetpointClient = refitSetpointClientFactory.Create(); } public async Task> GetCurrent(IEnumerable setpointKeys, CancellationToken token) diff --git a/DD.Persistence.Client/DependencyInjection.cs b/DD.Persistence.Client/DependencyInjection.cs index ab4d80f..53791bb 100644 --- a/DD.Persistence.Client/DependencyInjection.cs +++ b/DD.Persistence.Client/DependencyInjection.cs @@ -18,11 +18,12 @@ public static class DependencyInjection { services.AddSingleton(typeof(IRefitClientFactory<>), typeof(RefitClientFactory<>)); services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); - //services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + //services.AddTransient(); + //services.AddTransient, TimeSeriesClient<>>(); + //services.AddTransient(); + //services.AddTransient(); return services; } } diff --git a/DD.Persistence.Client/PersistenceClientFactory.cs b/DD.Persistence.Client/PersistenceClientFactory.cs index 1ebfbd5..c48424c 100644 --- a/DD.Persistence.Client/PersistenceClientFactory.cs +++ b/DD.Persistence.Client/PersistenceClientFactory.cs @@ -47,15 +47,15 @@ namespace DD.Persistence.Client /// Получить клиент для работы с уставками /// /// - public ISetpointClient GetSetpointClient() - { - var logger = provider.GetRequiredService>(); + //public ISetpointClient GetSetpointClient() + //{ + // var logger = provider.GetRequiredService>(); - var restClient = RestService.For(httpClient, RefitSettings); - var client = new SetpointClient(restClient, logger); + // var restClient = RestService.For(httpClient, RefitSettings); + // var client = new SetpointClient(restClient, logger); - return client; - } + // return client; + //} /// /// Получить клиент для работы с технологическими сообщениями @@ -133,14 +133,14 @@ namespace DD.Persistence.Client /// Получить клиент для работы c системами /// /// - public IDataSourceSystemClient GetDataSourceSystemClient() - { - var logger = provider.GetRequiredService>(); + //public IDataSourceSystemClient GetDataSourceSystemClient() + //{ + // var logger = provider.GetRequiredService>(); - var restClient = RestService.For(httpClient, RefitSettings); - var client = new DataSourceSystemClient(restClient, logger); + // var restClient = RestService.For(httpClient, RefitSettings); + // var client = new DataSourceSystemClient(restClient, logger); - return client; - } + // return client; + //} } } diff --git a/DD.Persistence.Client/RefitClientFactory.cs b/DD.Persistence.Client/RefitClientFactory.cs index 2b010e2..758f79d 100644 --- a/DD.Persistence.Client/RefitClientFactory.cs +++ b/DD.Persistence.Client/RefitClientFactory.cs @@ -20,9 +20,10 @@ public class RefitClientFactory : IRefitClientFactory where T : IRefitClie /// /// /// - public RefitClientFactory(IConfiguration configuration, ILogger> logger) + public RefitClientFactory(IConfiguration configuration, ILogger> logger, HttpClient client) { - this.client = new HttpClient(); + //this.client = factory.CreateClient(); + this.client = client; var baseUrl = configuration.GetSection("ClientUrl").Get(); if (String.IsNullOrEmpty(baseUrl)) @@ -49,8 +50,6 @@ public class RefitClientFactory : IRefitClientFactory where T : IRefitClie /// public T Create() { - - return RestService.For(client, refitSettings); } } diff --git a/DD.Persistence.IntegrationTests/Controllers/DataSourceSystemControllerTest.cs b/DD.Persistence.IntegrationTests/Controllers/DataSourceSystemControllerTest.cs index 03d5b8a..853a549 100644 --- a/DD.Persistence.IntegrationTests/Controllers/DataSourceSystemControllerTest.cs +++ b/DD.Persistence.IntegrationTests/Controllers/DataSourceSystemControllerTest.cs @@ -6,6 +6,8 @@ using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Database.Entity; using DD.Persistence.Models; using Xunit; +using DD.Persistence.Client.Clients.Interfaces.Refit; +using Microsoft.Extensions.Logging; namespace DD.Persistence.IntegrationTests.Controllers { @@ -16,11 +18,12 @@ namespace DD.Persistence.IntegrationTests.Controllers private readonly IMemoryCache memoryCache; public DataSourceSystemControllerTest(WebAppFactoryFixture factory) : base(factory) { - var scope = factory.Services.CreateScope(); - var persistenceClientFactory = scope.ServiceProvider - .GetRequiredService(); + var refitClientFactory = scope.ServiceProvider + .GetRequiredService>(); + var logger = scope.ServiceProvider.GetRequiredService>(); - dataSourceSystemClient = persistenceClientFactory.GetDataSourceSystemClient(); + dataSourceSystemClient = scope.ServiceProvider + .GetRequiredService(); memoryCache = scope.ServiceProvider.GetRequiredService(); } diff --git a/DD.Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs b/DD.Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs index d79b6c0..27432f3 100644 --- a/DD.Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs +++ b/DD.Persistence.IntegrationTests/Controllers/SetpointControllerTest.cs @@ -4,6 +4,9 @@ using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Database.Model; using System.Net; using Xunit; +using DD.Persistence.Client.Clients.Interfaces.Refit; +using DD.Persistence.Client.Clients; +using Microsoft.Extensions.Logging; namespace DD.Persistence.IntegrationTests.Controllers { @@ -17,11 +20,12 @@ namespace DD.Persistence.IntegrationTests.Controllers } public SetpointControllerTest(WebAppFactoryFixture factory) : base(factory) { - var scope = factory.Services.CreateScope(); - var persistenceClientFactory = scope.ServiceProvider - .GetRequiredService(); + var refitClientFactory = scope.ServiceProvider + .GetRequiredService>(); + var logger = scope.ServiceProvider.GetRequiredService>(); - setpointClient = persistenceClientFactory.GetSetpointClient(); + setpointClient = scope.ServiceProvider + .GetRequiredService(); } [Fact] diff --git a/DD.Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs b/DD.Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs index 6db5853..6b33804 100644 --- a/DD.Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs +++ b/DD.Persistence.IntegrationTests/Controllers/WitsDataControllerTest.cs @@ -5,6 +5,9 @@ using System.Net; using Xunit; using DD.Persistence.Client.Clients.Interfaces; using DD.Persistence.Client; +using DD.Persistence.Client.Clients.Interfaces.Refit; +using DD.Persistence.Client.Clients; +using Microsoft.Extensions.Logging; namespace DD.Persistence.IntegrationTests.Controllers; public class WitsDataControllerTest : BaseIntegrationTest @@ -13,11 +16,12 @@ public class WitsDataControllerTest : BaseIntegrationTest public WitsDataControllerTest(WebAppFactoryFixture factory) : base(factory) { - var scope = factory.Services.CreateScope(); - var persistenceClientFactory = scope.ServiceProvider - .GetRequiredService(); + var refitClientFactory = scope.ServiceProvider + .GetRequiredService>(); + var logger = scope.ServiceProvider.GetRequiredService>(); - witsDataClient = persistenceClientFactory.GetWitsDataClient(); + witsDataClient = scope.ServiceProvider + .GetRequiredService(); } [Fact] diff --git a/DD.Persistence.IntegrationTests/WebAppFactoryFixture.cs b/DD.Persistence.IntegrationTests/WebAppFactoryFixture.cs index d953f50..df6deb1 100644 --- a/DD.Persistence.IntegrationTests/WebAppFactoryFixture.cs +++ b/DD.Persistence.IntegrationTests/WebAppFactoryFixture.cs @@ -45,7 +45,8 @@ public class WebAppFactoryFixture : WebApplicationFactory return new TestHttpClientFactory(this); }); - services.AddSingleton(); + services.AddHttpClient(); + //services.AddSingleton(); services.AddPersistenceClients(); var serviceProvider = services.BuildServiceProvider(); @@ -57,9 +58,6 @@ public class WebAppFactoryFixture : WebApplicationFactory dbContext.Database.EnsureCreatedAndMigrated(); dbContext.SaveChanges(); }); - - builder.UseUrls("http://localhost:5000"); - } public override async ValueTask DisposeAsync()