Is not related to any version.
C#
Is it possible to integrate Microsoft.Azure.Functions.Extensions with Autofac using this approach?
The idea is to register the dependencies using Autofac and resolve them in the functions.
So far I've tried using the IServiceCollection.AddAutofac() method of Autofac.Extensions.DependencyInjection with the following implementation:
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddAutofac(b => b.RegisterModule<MyModule>());
}
But it fails when resolving the registered dependencies in the functions class:
public class MyFunctions
{
private readonly IMyDependency myDependency;
public QnASynchronizationFunctions(IMyDependency myDependency,)
{
this.myDependency = myDependency;
}
[FunctionName("MyFunction")]
public async Task MyFunction([TimerTrigger(KnownTimerConfigs.OnTheHour, RunOnStartup = true)]TimerInfo timer)
{
myDependency.Handle();
}
Hi, I have the same issue, I'm interested to get the answer too.
Error message returned is:
Executed 'MyFunction' (Failed, Id=1fbfba73-3dc8-482d-b71a-0a3a02e61481)
[29-May-19 18:45:44] Microsoft.Extensions.DependencyInjection.Abstractions: Unable to resolve service for type 'MyProject.Services.IMyService' while attempting to activate 'MyProject.MyFunction'.
Most helpful comment
Hi, I have the same issue, I'm interested to get the answer too.
Error message returned is: