using ExcelDna.IntelliSense; using RhSolutions.Tools; using System.Net; #if !NET472 using System.Runtime.Versioning; #endif namespace RhSolutions.AddIn; #if !NET472 [SupportedOSPlatform("windows")] #endif public sealed class RhSolutionsAddIn : IExcelAddIn { 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((Application)ExcelDnaUtil.Application) .AddSingleton() .AddSingleton() .AddTransient() .AddTransient() .AddTransient(); ServiceProvider = Services.BuildServiceProvider(); Configuration = ServiceProvider.GetService(); Excel = ServiceProvider.GetService(); IntelliSenseServer.Install(); EventsUtil.Initialize(); ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; } public void AutoClose() { IntelliSenseServer.Uninstall(); EventsUtil.Uninitialize(); } }