首页 > 解决方案 > 如何在 .net core 2.2 中使用依赖注入添加 IEndpointsOperations 接口

问题描述

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

未处理的异常: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_SystemCancellation_String_System_Collections_Generic_IList

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

解决方案


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

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

    }

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


推荐阅读