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

63 lines
2.2 KiB
C#
Raw Normal View History

2023-04-06 21:38:01 +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
{
2024-11-06 23:43:00 +03:00
public static Application Excel { get; private set; }
public static ServiceProvider ServiceProvider { get; private set; }
public static IAddInConfiguration Configuration { get; private set; }
public void AutoOpen()
{
IServiceCollection Services = new ServiceCollection();
Services.AddHttpClient()
.AddMemoryCache()
.AddSingleton((Application)ExcelDnaUtil.Application)
.AddSingleton<IAddInConfiguration, AddInConfiguration>()
.AddSingleton<IDatabaseClient, DatabaseClient>()
.AddSingleton<ICurrencyClient, CurrencyClient>()
.AddTransient<IFileDialog, FileDialog>();
Services.AddSingleton<WriterFactory>();
Services.AddTransient<NewPriceWriter>()
.AddTransient<IWriter, NewPriceWriter>(s => s.GetService<NewPriceWriter>());
Services.AddTransient<DxfWriter>()
.AddTransient<IWriter, DxfWriter>(s => s.GetService<DxfWriter>());
Services.AddTransient<CurrentPriceWriter>()
.AddTransient<IWriter, CurrentPriceWriter>(s => s.GetService<CurrentPriceWriter>());
Services.AddSingleton<ReaderFactory>();
Services.AddTransient<ExcelReader>()
.AddTransient<IReader, ExcelReader>(s => s.GetService<ExcelReader>());
Services.AddTransient<GuessReader>()
.AddTransient<IReader, GuessReader>(s => s.GetService<GuessReader>());
Services.AddSingleton<FittingsCalculatorFactory>();
Services.AddTransient<CouplingsCalculator>()
.AddTransient<IFittingsCalculator, CouplingsCalculator>(s => s.GetService<CouplingsCalculator>());
Services.AddTransient<SleevesCalculator>()
.AddTransient<IFittingsCalculator, SleevesCalculator>(s => s.GetService<SleevesCalculator>());
2024-11-08 09:23:36 +03:00
2024-11-09 22:34:58 +03:00
Services.AddTransient<IOcrClient, YandexOcrClient>();
2024-11-06 23:43:00 +03:00
Services.AddSingleton<ToolFactory>();
ServiceProvider = Services.BuildServiceProvider();
Configuration = ServiceProvider.GetService<IAddInConfiguration>();
Excel = ServiceProvider.GetService<Application>();
EventsUtil.Initialize();
ServicePointManager.SecurityProtocol =
SecurityProtocolType.Tls12;
ServicePointManager.DefaultConnectionLimit = 50;
}
public void AutoClose()
{
EventsUtil.Uninitialize();
}
2021-11-29 15:50:24 +03:00
}