-
Notifications
You must be signed in to change notification settings - Fork 186
Extension startup hook
The dotnet-isolated worker programming model supports the ability for worker extensions to participate in the startup routine of the function application, thus enabling extension authors to register additional services relevant to the extension.
Follow the below steps to participate in the startup process
-
Add a reference to the latest version of Microsoft.Azure.Functions.Worker.Core package in your extension project.
-
Create a class which derives from
WorkerExtensionStartup
. Override theConfigure
method. An instance ofIFunctionsWorkerApplicationBuilder
will be passed into theConfigure
method, which can be used to configure the function worker application builder options.- The class should be public.
- The class should have a public parameterless constructor.
-
Use the
WorkerExtensionStartup
assembly level attribute to specify the startup implementation class created in step 1.
Here is an example startup implementation which register the StampHttpHeadersMiddleware
middleware and the IFooService
. You can also see that we are using the WorkerExtensionStartup
attribute to specify the type information of our extension startup class.
[assembly: WorkerExtensionStartup(typeof(MyHttpExtensionStartup))]
namespace Microsoft.Azure.Functions.Worker.Extensions.Http
{
public class MyHttpExtensionStartup : WorkerExtensionStartup
{
public override void Configure(IFunctionsWorkerApplicationBuilder applicationBuilder)
{
applicationBuilder.UseMiddleware<StampHttpHeadersMiddleware>();
applicationBuilder.Services.AddSingleton<IMyFooService, MyFooService>();
}
}
}
Testing extensions end to end
When testing the extension with the startup hook in an isolated-worker function application, make sure to use the latest version of the Microsoft.Azure.Functions.Worker.Sdk package.