Functions.Worker.ContextAccessor
2.0.0
dotnet add package Functions.Worker.ContextAccessor --version 2.0.0
NuGet\Install-Package Functions.Worker.ContextAccessor -Version 2.0.0
<PackageReference Include="Functions.Worker.ContextAccessor" Version="2.0.0" />
paket add Functions.Worker.ContextAccessor --version 2.0.0
#r "nuget: Functions.Worker.ContextAccessor, 2.0.0"
// Install Functions.Worker.ContextAccessor as a Cake Addin #addin nuget:?package=Functions.Worker.ContextAccessor&version=2.0.0 // Install Functions.Worker.ContextAccessor as a Cake Tool #tool nuget:?package=Functions.Worker.ContextAccessor&version=2.0.0
FunctionContext accessor .NET 5+ (.NET isolated) Azure Functions
Usage
Add to your Program.cs
file
.ConfigureFunctionsWorkerDefaults(applicationBuilder => applicationBuilder.UseFunctionContextAccessor())
and
.ConfigureServices(services => services.AddFunctionContextAccessor())
Final result would look something like this:<br/>
Program.cs
using Functions.Worker.ContextAccessor;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
var host = new HostBuilder()
.ConfigureAppConfiguration(configBuilder => configBuilder.AddEnvironmentVariables())
.ConfigureFunctionsWorkerDefaults(applicationBuilder => applicationBuilder.UseFunctionContextAccessor())
.ConfigureServices(services => services.AddFunctionContextAccessor())
.ConfigureServices(Startup.Configure)
.UseDefaultServiceProvider((_, options) =>
{
options.ValidateScopes = true;
options.ValidateOnBuild = true;
})
.Build();
host.Run();
Scope Validation
It is strongly recommended that scopes are validated as seen by the inclusion of
.UseDefaultServiceProvider((_, options) =>
{
options.ValidateScopes = true;
options.ValidateOnBuild = true;
})
because unintended behavior may occur when there's no validation.
Why
As of this writting, the interface IFunctionsWorkerMiddleware does NOT have a IFunctionsWorkerMiddlewareFactory counterpart and gets registered as a singleton. As opposed to ASP.NET Core's IMiddleware which DOES have an IMiddlewareFactory counterpart and will allow the middleware to be registered with either a scoped or instance lifetime. This resulted in scoped access to the FunctionContext only being available to the function method and context information cannot be easily injected into other parts of the application.
This library is modeled after the implementation of HttpContextAccessor (usage seen here) and is inspired by @dolphinspired's gist.
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
- Microsoft.Azure.Functions.Worker.Core (>= 1.8.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Functions.Worker.ContextAccessor:
Package | Downloads |
---|---|
Optsol.EventDriven.Components.Core.Application
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
2.0.0 Target NetStandard 2.0 instead of NET 5;
1.0.0 Initial Release