Azure / Azure/azure-functions-host

Integrate Microsoft.Azure.Functions.Extensions with Autofac

Open
#4,429 1 comment 12 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

#### Is your question related to a specific version? If so, please specify:
Is not related to any version.

#### What language does your question apply to? (e.g. C#, JavaScript, Java, All)
C#

#### Question
Is it possible to integrate `Microsoft.Azure.Functions.Extensions` with Autofac using [this](https://docs.microsoft.com/en-us/azure/azure-functions/functions-dotnet-dependency-injection) 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());
}
```
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();
}
```

Contributor guide

Open the contributing guide

Research direction

Start with the Microsoft.Azure.Functions.Extensions dependency-injection documentation and the Configure(IFunctionsHostBuilder) example in the issue, then trace how AddAutofac from Autofac.Extensions.DependencyInjection is expected to build the container. The issue does not name repository files or tests; completion would require defining and validating a supported Autofac integration that resolves constructor dependencies in functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, csharp
Domain
backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.