Azure Function run code on startup

At the 2019 Build conference, Microsoft released the functionality to have a callable method when the Azure Function app starts up. This can be used for registering DI classes, creating static DB connections, etc.

The documentation for these new features can be found at Azure Function Dependency Injection


You can implement an IExtensionConfigProvider. Those will be scanned and execute on "Startup".

using Microsoft.Azure.WebJobs.Host.Config;
namespace MyFunctionApp
{
  public class Startup : IExtensionConfigProvider
  {
     public void Initialize(ExtensionConfigContext context)
     {
        // Put your intialization code here.
     }
  }
}