Add Application Singleton

This commit is contained in:
Sergey Chebotar 2023-03-28 07:33:13 +03:00
parent 15dd27fb68
commit 68512dba2b

View File

@ -8,7 +8,7 @@ using System.Net;
namespace RhSolutions.AddIn
{
public class RhSolutionsAddIn : IExcelAddIn
public sealed class RhSolutionsAddIn : IExcelAddIn
{
public static Application Excel { get; private set; }
public static ServiceProvider ServiceProvider { get; set; }
@ -17,15 +17,16 @@ namespace RhSolutions.AddIn
public void AutoOpen()
{
IServiceCollection Services = new ServiceCollection();
Excel = (Application)ExcelDnaUtil.Application;
Services.AddHttpClient()
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
.AddSingleton<IAddInConfiguration, AddInConfiguration>();
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
.AddSingleton(ExcelDnaUtil.Application);
ServiceProvider = Services.BuildServiceProvider();
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
Excel = ServiceProvider.GetService<Application>();
IntelliSenseServer.Install();
EventsUtil.Initialize();