I am using Azure Function(v3), I can register dependencies in startup.cs with both IWebJobsStartup and FunctionsStartup.
But which one we should use?
Registerd dependencies with IWebJobsStartup
[assembly: WebJobsStartup(typeof(Startup))]
namespace Notifications.Receiver
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
builder.Services.AddTransient<IEventValidator, EventValidator>();
builder.Services.AddTransient<IEventReceiverHandler, EventReceiverHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto,InvoiceMessageEvent>, InvoiceMessageEventHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto, InvoiceFileEvent>, InvoiceFileEventHandler>();
builder.Services.AddSingleton<IMessageBusFactory, AzureServiceBusFactory>();
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
}
}
}
Same dependencies I can also register with FunctionsStartup
[assembly: FunctionsStartup(typeof(Startup))]
namespace Notifications.Receiver
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.AddTransient<IEventValidator, EventValidator>();
builder.Services.AddTransient<IEventReceiverHandler, EventReceiverHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto,InvoiceMessageEvent>, InvoiceMessageEventHandler>();
builder.Services.AddTransient<IEventHandler<InvoiceResultDto, InvoiceFileEvent>, InvoiceFileEventHandler>();
builder.Services.AddSingleton<IMessageBusFactory, AzureServiceBusFactory>();
builder.Services.Configure<KestrelServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
}
}
}