RhSolutions-AddIn/RhSolutions.AddIn/AddIn/RhSolutionsAddIn.cs

38 lines
1.1 KiB
C#
Raw Normal View History

2023-03-28 10:03:19 +03:00
using ExcelDna.IntelliSense;
2022-12-20 12:58:30 +03:00
using System.Net;
2021-12-24 16:22:03 +03:00
2023-03-28 10:03:19 +03:00
namespace RhSolutions.AddIn;
public sealed class RhSolutionsAddIn : IExcelAddIn
2021-11-29 15:50:24 +03:00
{
2023-03-28 10:03:19 +03:00
public static Application Excel { get; private set; }
public static ServiceProvider ServiceProvider { get; set; }
public static IAddInConfiguration Configuration { get; set; }
public void AutoOpen()
{
IServiceCollection Services = new ServiceCollection();
Services.AddHttpClient()
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
.AddSingleton((Application)ExcelDnaUtil.Application);
ServiceProvider = Services.BuildServiceProvider();
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
Excel = ServiceProvider.GetService<Application>();
IntelliSenseServer.Install();
EventsUtil.Initialize();
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12;
}
public void AutoClose()
2021-11-29 15:50:24 +03:00
{
2023-03-28 10:03:19 +03:00
IntelliSenseServer.Uninstall();
EventsUtil.Uninitialize();
2021-11-29 15:50:24 +03:00
}
}