43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using ExcelDna.Integration;
|
|
using ExcelDna.IntelliSense;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Office.Interop.Excel;
|
|
using RhSolutions.Services;
|
|
using System;
|
|
using System.Net;
|
|
|
|
namespace RhSolutions.AddIn
|
|
{
|
|
public 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();
|
|
Excel = (Application)ExcelDnaUtil.Application;
|
|
|
|
Services.AddHttpClient()
|
|
.AddSingleton<IDatabaseClient, RhDatabaseClient>()
|
|
.AddSingleton<IAddInConfiguration, AddInConfiguration>();
|
|
|
|
ServiceProvider = Services.BuildServiceProvider();
|
|
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
|
|
|
|
IntelliSenseServer.Install();
|
|
EventsUtil.Initialize();
|
|
|
|
ServicePointManager.SecurityProtocol =
|
|
SecurityProtocolType.Tls12;
|
|
}
|
|
|
|
public void AutoClose()
|
|
{
|
|
IntelliSenseServer.Uninstall();
|
|
EventsUtil.Uninitialize();
|
|
}
|
|
}
|
|
}
|