Functions.Worker.ContextAccessor
1.0.0
See the version list below for details.
dotnet add package Functions.Worker.ContextAccessor --version 1.0.0
NuGet\Install-Package Functions.Worker.ContextAccessor -Version 1.0.0
<PackageReference Include="Functions.Worker.ContextAccessor" Version="1.0.0" />
paket add Functions.Worker.ContextAccessor --version 1.0.0
#r "nuget: Functions.Worker.ContextAccessor, 1.0.0"
// Install Functions.Worker.ContextAccessor as a Cake Addin #addin nuget:?package=Functions.Worker.ContextAccessor&version=1.0.0 // Install Functions.Worker.ContextAccessor as a Cake Tool #tool nuget:?package=Functions.Worker.ContextAccessor&version=1.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 is compatible. 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. |
-
net5.0
- Microsoft.Azure.Functions.Worker.Core (>= 1.0.0)
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.
1.0.0 Initial Release