using Microsoft.Extensions.DependencyInjection; using ExcelAddIn.Services; using System.Text; public class MyAddIn : IExcelAddIn { public static ServiceProvider ServiceProvider { get; private set; } public void AutoOpen() { Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); IServiceCollection Services = new ServiceCollection(); Services.AddHttpClient() .AddSingleton<ICurrencyClient, CurrencyClient>(); ServiceProvider = Services.BuildServiceProvider(); } public void AutoClose() { } }