【问题标题】:How to add IEndpointsOperations interface using dependency injection in .net core 2.2如何在 .net core 2.2 中使用依赖注入添加 IEndpointsOperations 接口
【发布时间】:2019-08-20 09:13:30
【问题描述】:

我想使用IEndpointOperations 接口中的LoadContentAsync 方法和.net core 2.2 中可用的依赖注入。请分享一些代码示例。我尝试在Startup.cs 中添加AddSingleton/AddTransient 并尝试在控制器构造函数中使用它。但我得到以下错误,

未处理的异常:System.ArgumentException:无法实例化 实现类型 服务类型的“Microsoft.Azure.Management.Cdn.IEndpointsOperations” 'Microsoft.Azure.Management.Cdn.IEndpointsOperations'。

使用的具体方法在下面的链接中, https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.cdn.endpointsoperationsextensions.loadcontentasync?view=azure-dotnet#Microsoft_Azure_Management_Cdn_EndpointsOperationsExtensions_LoadContentAsync_Microsoft_Azure_Management_Cdn_IEndpointsOperations_System_String_System_String_System_String_System_Collections_Generic_IList_System_String__System_Threading_CancellationToken_

【问题讨论】:

    标签: c# azure-cdn .net-core-2.2


    【解决方案1】:

    需要在启动类中让系统知道一个接口的实现类。例如:

        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.Services.AddSingleton<IClass1, Class1>();
    
        }
    

    我可以知道接口IEndpointsOperations的实现类吗?

    【讨论】:

    • EndpointsOperations 是实现类,但 internal 在 Microsoft.Azure.Management.Cdn 库中。
    • 这就是问题所在。由于它是一个内部类,我建议你从 CdnManagementClient 实例中获取实例。
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 2019-04-13
    • 2019-03-14
    • 2020-04-17
    • 2019-07-22
    • 1970-01-01
    • 2016-05-22
    相关资源
    最近更新 更多