aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs13
-rw-r--r--RhSolutions.AddIn/RhSolutions.AddIn.csproj11
-rw-r--r--RhSolutions.AddIn/Services/RhDatabaseClient.cs6
3 files changed, 20 insertions, 10 deletions
diff --git a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
index a4c6019..a306576 100644
--- a/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
+++ b/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs
@@ -1,21 +1,24 @@
using ExcelDna.Integration;
using ExcelDna.IntelliSense;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Office.Interop.Excel;
using RhSolutions.Services;
using System.Net;
-using System.Net.Http;
namespace RhSolutions.AddIn
{
- class RhSolutionsAddIn : IExcelAddIn
+ public class RhSolutionsAddIn : IExcelAddIn
{
public static Application Excel { get; private set; }
- public static HttpClient HttpClient { get; private set; }
+ public static ServiceProvider ServiceProvider { get; set; }
public void AutoOpen()
{
+ IServiceCollection Services = new ServiceCollection();
+ Services.AddHttpClient();
+ ServiceProvider = Services.BuildServiceProvider();
+
Excel = (Application)ExcelDnaUtil.Application;
- HttpClient = new HttpClient();
IntelliSenseServer.Install();
RegistryUtil.Initialize();
EventsUtil.Initialize();
@@ -29,7 +32,7 @@ namespace RhSolutions.AddIn
IntelliSenseServer.Uninstall();
RegistryUtil.Uninitialize();
EventsUtil.Uninitialize();
- HttpClient.Dispose();
+ //HttpClient.Dispose();
}
}
}
diff --git a/RhSolutions.AddIn/RhSolutions.AddIn.csproj b/RhSolutions.AddIn/RhSolutions.AddIn.csproj
index 9b88245..f5498c0 100644
--- a/RhSolutions.AddIn/RhSolutions.AddIn.csproj
+++ b/RhSolutions.AddIn/RhSolutions.AddIn.csproj
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
- <TargetFrameworks>net472;net6.0-windows</TargetFrameworks>
+ <TargetFrameworks>net472;net6.0-windows7.0</TargetFrameworks>
<LangVersion>10</LangVersion>
<OutputType>Library</OutputType>
<RootNamespace>RhSolutions.AddIn</RootNamespace>
@@ -13,13 +13,18 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
- <PackageReference Include="ExcelDna.AddIn" Version="1.6.0" />
+ <PackageReference Include="ExcelDna.AddIn" Version="1.6.0">
+ <TreatAsUsed>true</TreatAsUsed>
+ </PackageReference>
<PackageReference Include="ExcelDna.Integration" Version="1.6.0" />
<PackageReference Include="ExcelDna.IntelliSense" Version="1.6.0" />
<PackageReference Include="ExcelDna.Interop" Version="15.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
+ <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0">
+ <TreatAsUsed>true</TreatAsUsed>
+ </PackageReference>
+ <PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="RhSolutions.Sku" Version="0.1.1" />
- <PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
</Project> \ No newline at end of file
diff --git a/RhSolutions.AddIn/Services/RhDatabaseClient.cs b/RhSolutions.AddIn/Services/RhDatabaseClient.cs
index 70530ae..43463ca 100644
--- a/RhSolutions.AddIn/Services/RhDatabaseClient.cs
+++ b/RhSolutions.AddIn/Services/RhDatabaseClient.cs
@@ -1,4 +1,5 @@
-using Newtonsoft.Json;
+using Microsoft.Extensions.DependencyInjection;
+using Newtonsoft.Json;
using RhSolutions.AddIn;
using RhSolutions.Models;
using System;
@@ -25,7 +26,8 @@ namespace RhSolutions.Services
request = @"https://rh.cebotari.ru/api/search?query=" + line;
}
- var response = await RhSolutionsAddIn.HttpClient.GetAsync(request);
+ var client = RhSolutionsAddIn.ServiceProvider.GetRequiredService<HttpClient>();
+ var response = await client.GetAsync(request);
try
{