I have an Azure Functions app that uses custom parameter bindings that were initialised in the [WebJobsStartup] - how do I migrate these to the new [FunctionsStartup] way of doing things?
In the [WebJobsStartup] the bindings were registered by the call to builder.AddExtension with .AddBindingRule
Now the new Azure SDK says to use [FunctionsStartup] - how do I hook in (or replace) .AddBindingRule in this?
The FunctionsStartup implementation looks like:-
[assembly: FunctionsStartup(typeof(EventSourcingOnAzureFunctions.Common.Startup))]
namespace EventSourcingOnAzureFunctions.Common
{
public class Startup
: FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.AddAppSettingsToConfiguration();
// Initialise any common services
CQRSAzureBindings.InitializeServices(builder.Services);
builder.Services.AddWebJobs(ConfigureWebJobs );
}
public void ConfigureWebJobs(JobHostOptions hostOptions)
{
}
}
And the way it used to register the binding rules is like:-
/// <summary>
/// Initailise any common dependency injection configuration settings
/// </summary>
/// <param name="context"></param>
public static void InitializeInjectionConfiguration(ExtensionConfigContext context)
{
// Set up the dependency injection stuff for the custom bindings
// 1: EventStream
context
.AddBindingRule<EventStreamAttribute>()
.BindToInput<EventStream>(BuildEventStreamFromAttribute)
;
}
If I run the function app as is the binding rules code does not get called and as a result the function indexing fails with e.g.
Microsoft.Azure.WebJobs.Host: Error indexing method 'DepositMoney'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'bankAccountEvents' to type EventStream. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.).