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'.
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
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()
{
}
}
Fixed by updating the nuget package Microsoft.NET.Sdk.Functions from 1.0.24 -> 1.0.26
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With