Autofac.Extensions.DependencyInjection.AzureFunctions
6.0.0.44
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
<PackageReference Include="Autofac.Extensions.DependencyInjection.AzureFunctions" Version="6.0.0.44" />
paket add Autofac.Extensions.DependencyInjection.AzureFunctions --version 6.0.0.44
#r "nuget: Autofac.Extensions.DependencyInjection.AzureFunctions, 6.0.0.44"
// 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.
Please file issues and pull requests for this package in this repository rather than in the Autofac core repo.
- Documentation - .NET Core Integration
- Documentation - ASP.NET Core Integration
- NuGet
- Contributing - You can report problems and feature requests creating issues and pull requests on this project.
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 theIFunctionsHostBuilder
, callUseAutofacServiceProviderFactory(ConfigureContainer)
to hook Autofac into the startup pipeline. - In the
ConfigureContainer
method of yourStartup
class register things directly into an AutofacContainerBuilder
. - 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 | Versions 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. |
-
.NETStandard 2.0
- Autofac.Extensions.DependencyInjection (>= 6.0.0)
- Microsoft.Azure.Functions.Extensions (>= 1.0.0)
- Microsoft.Extensions.Logging.Console (>= 3.1.2)
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 | 248,511 | 10/14/2022 |
7.2.0.88 | 111,643 | 5/19/2022 |
6.0.0.81 | 257,047 | 8/11/2021 |
6.0.0.78 | 53,248 | 5/21/2021 |
6.0.0.73 | 18,169 | 4/27/2021 |
6.0.0.71 | 26,712 | 3/24/2021 |
6.0.0.53 | 47,732 | 10/6/2020 |
6.0.0.51 | 38,712 | 9/8/2020 |
6.0.0.44 | 142,883 | 4/6/2020 |
6.0.0.42 | 847 | 3/13/2020 |
6.0.0.40 | 880 | 3/13/2020 |
6.0.0.38 | 3,373 | 3/12/2020 |
Release notes are at https://github.com/junalmeida/autofac-azurefunctions/releases