Autofac.Extensions.DependencyInjection.AzureFunctions 6.0.0.44

There is a newer version of this package available.
See the version list below for details.
dotnet add package Autofac.Extensions.DependencyInjection.AzureFunctions --version 6.0.0.44
NuGet\Install-Package Autofac.Extensions.DependencyInjection.AzureFunctions -Version 6.0.0.44
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Autofac.Extensions.DependencyInjection.AzureFunctions" Version="6.0.0.44" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Autofac.Extensions.DependencyInjection.AzureFunctions --version 6.0.0.44
#r "nuget: Autofac.Extensions.DependencyInjection.AzureFunctions, 6.0.0.44"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Autofac.Extensions.DependencyInjection.AzureFunctions as a Cake Addin
#addin nuget:?package=Autofac.Extensions.DependencyInjection.AzureFunctions&version=6.0.0.44

// Install Autofac.Extensions.DependencyInjection.AzureFunctions as a Cake Tool
#tool nuget:?package=Autofac.Extensions.DependencyInjection.AzureFunctions&version=6.0.0.44

Autofac.Extensions.DependencyInjection.AzureFunctions

Autofac is an IoC container for Microsoft .NET. It manages the dependencies between classes so that applications stay easy to change as they grow in size and complexity. This is achieved by treating regular .NET classes as components.

NuGet

Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.

Get Started in Azure Functions

This quick start shows how to use the UseAutofacServiceProviderFactory integration to help automatically build the root service provider for you.

  • Reference the Autofac.Extensions.DependencyInjection.AzureFunctions package from NuGet.
  • Create your Startup class, following the documentation on how to Use dependency injection in .NET Azure Functions
  • In your Configure method, where you configure the IFunctionsHostBuilder, call UseAutofacServiceProviderFactory(ConfigureContainer) to hook Autofac into the startup pipeline.
  • In the ConfigureContainer method of your Startup class register things directly into an Autofac ContainerBuilder.
  • If you want to use functions declared in referenced projects, add <FunctionsInDependencies>true</FunctionsInDependencies> to the <PropertyGroup> of your main Azure Functions project.

The IServiceProvider will automatically be created for you, so there's nothing you have to do but register things.

using Microsoft.Azure.Functions.Extensions.DependencyInjection;

[assembly: FunctionsStartup(typeof(Startup))]

public class Startup : FunctionsStartup
{
    public override void Configure(IFunctionsHostBuilder builder)
    {
        builder
            .UseAppSettings() // this is optional, this will bind IConfiguration in the container.
            .UseAutofacServiceProviderFactory(ConfigureContainer);
    }

    private void ConfigureContainer(ContainerBuilder builder)
    {
        builder
            .Register(activator =>
            {
                // Example on how to bind settings from appsettings.json
                // to a class instance
                var mySettings = new MySettings();

                var config = activator.Resolve<IConfiguration>();
                config.GetSection(nameof(MySettings)).Bind(mySettings);

                return mySettings;
            })
            .AsSelf()
            .SingleInstance();

        // Register all functions that resides in a given namespace
        // The function class itself will be created using autofac
        builder
            .RegisterAssemblyTypes(typeof(Startup).Assembly)
            .InNamespace("MyNamespace.Functions")
            .AsSelf() // Azure Functions core code resolves a function class by itself.
            .InstancePerTriggerRequest() // This will scope nested dependencies to each function execution

        builder
            .RegisterAssemblyTypes(typeof(Startup).Assembly)
            .InNamespace("MyNamespace.Services")
            .AsImplementedInterfaces()
            .InstancePerTriggerRequest();

    }
}

This is a basic function example, observe that classes and functions are not declared as static:

    public class Function1 : Disposable
    {
        public Function1(IService1 service1, ILogger logger)
        {
            // ...
        }

        [FunctionName(nameof(Function1))]
        public async Task Run([QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")]string myQueueItem)
        {
            await Task.Delay(2000);
            _logger.LogInformation($"C# Queue trigger function processed: {myQueueItem}");
        }

        // ...
    }

Get Help

Need help with Autofac? We have a documentation site as well as API documentation. We're ready to answer your questions on Stack Overflow or check out the discussion forum.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Autofac.Extensions.DependencyInjection.AzureFunctions:

Package Downloads
Functionless

Write More Code, Less Azure Functions. Functionless is a library to ease your Azure Function development by minimizing the abstraction of your long-running services, processes, workflows, etc.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.2.0.92 154,876 10/14/2022
7.2.0.88 97,230 5/19/2022
6.0.0.81 228,528 8/11/2021
6.0.0.78 51,111 5/21/2021
6.0.0.73 18,050 4/27/2021
6.0.0.71 24,142 3/24/2021
6.0.0.53 45,572 10/6/2020
6.0.0.51 33,454 9/8/2020
6.0.0.44 140,746 4/6/2020
6.0.0.42 817 3/13/2020
6.0.0.40 852 3/13/2020
6.0.0.38 3,258 3/12/2020