Избавиться от System.Configuration.ConfigurationManager в DD.Persistence.Client #23

Merged
ng.frolov merged 2 commits from fix/#884-remove-configurationManager into dev 2025-02-05 10:25:15 +05:00
4 changed files with 24 additions and 6 deletions

View File

@ -21,5 +21,5 @@
"grantType": "password", "grantType": "password",
"http://schemas.xmlsoap.org/ws/2005/05/identity /claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6" "http://schemas.xmlsoap.org/ws/2005/05/identity /claims/nameidentifier": "7d9f3574-6574-4ca3-845a-0276eb4aa8f6"
}, },
"ClientUrl": "http://localhost:5000/" "PeristenceClientUrl": "http://localhost:5000/"
} }

View File

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DD.Persistence.Client.CustomExceptions;
/// <summary>
/// Ошибка, которая выбрасывается в случае отсутствия необходимого свойства в appsettings.json
/// </summary>
public class AppSettingsPropertyNotFoundException : Exception
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public AppSettingsPropertyNotFoundException(string message)
: base(message) { }
}

View File

@ -52,7 +52,6 @@
<PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" /> <PackageReference Include="Microsoft.IdentityModel.Tokens" Version="8.3.0" />
<PackageReference Include="Refit" Version="8.0.0" /> <PackageReference Include="Refit" Version="8.0.0" />
<PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" /> <PackageReference Include="Refit.HttpClientFactory" Version="8.0.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.3.0" />
</ItemGroup> </ItemGroup>

View File

@ -1,9 +1,8 @@
using DD.Persistence.Client.Clients.Interfaces.Refit; using DD.Persistence.Client.Clients.Interfaces.Refit;
using DD.Persistence.Client.Helpers; using DD.Persistence.Client.CustomExceptions;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Refit; using Refit;
using System.Configuration;
using System.Text.Json; using System.Text.Json;
namespace DD.Persistence.Client; namespace DD.Persistence.Client;
@ -23,10 +22,10 @@ public class RefitClientFactory<T> : IRefitClientFactory<T> where T : IRefitClie
//this.client = factory.CreateClient(); //this.client = factory.CreateClient();
this.client = client; this.client = client;
var baseUrl = configuration.GetSection("ClientUrl").Get<string>(); var baseUrl = configuration.GetSection("PeristenceClientUrl").Get<string>();
if (String.IsNullOrEmpty(baseUrl)) if (String.IsNullOrEmpty(baseUrl))
{ {
var exception = new SettingsPropertyNotFoundException("В настройках конфигурации не указан адрес Persistence сервиса."); var exception = new AppSettingsPropertyNotFoundException("В настройках конфигурации не указан адрес Persistence сервиса.");
logger.LogError(exception.Message); logger.LogError(exception.Message);