[英]Azure function 2 Dependency injection throwing error
I have a simple trigger that is bound to a Service bus topic.我有一个绑定到服务总线主题的简单触发器。 I am trying to inject another service into the trigger but i am receiving an error:
我正在尝试将另一个服务注入触发器,但我收到一个错误:
Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'AzureSearchSBTrigger.SimpleClass' while attempting to activate 'AzureSearchSBTrigger.AzureServiceTrigger'.
Microsoft.Extensions.DependencyInjection.Abstractions:尝试激活“AzureSearchSBTrigger.AzureServiceTrigger”时无法解析“AzureSearchSBTrigger.SimpleClass”类型的服务。
If it remove the constructor the trigger works correctly and i can receive messages, etc.如果它删除构造函数触发器工作正常,我可以接收消息等。
This is an Azure function 2 (.net core) with Function Runtime Version: 2.0.12332.0这是一个 Azure 函数 2(.net 核心),函数运行时版本:2.0.12332.0
This is how it is setup (and not working)这是它的设置方式(并且不工作)
The main function :主要功能:
public AzureServiceTrigger(SimpleClass apiClient)
{
}
[FunctionName("AzureServiceTrigger")]
public async Task Run([ServiceBusTrigger("","",Connection = "SBConnectionString")]Message myQueueItem, ILogger log)
{
}
StartUp启动
[assembly: WebJobsStartup(typeof(StartUp))]
namespace AzureSearchSBTrigger
{
internal class StartUp : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
builder.Services.AddSingleton<SimpleClass>();
}
}
}
Simple Class简单类
public class SimpleClass
{
public void Somethingsimple()
{
}
}
通过从 1.0.24 -> 1.0.26 更新 nuget 包 Microsoft.NET.Sdk.Functions 来修复
Use anything below Microsoft.NET.Sdk.Functions 3.0.1.使用低于 Microsoft.NET.Sdk.Functions 3.0.1 的任何内容。 I had 3.0.2 and I got this error, I had to downgrade but than again am using ASP.NetCore 2.2, so not sure if that has much to do with it
我有 3.0.2 并且出现此错误,我不得不降级,但再次使用 ASP.NetCore 2.2,所以不确定这是否与它有很大关系
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.