Azure Function run code on startup

前端 未结 2 790
傲寒
傲寒 2020-12-17 23:45

I am trying to find a way to run some code one time (where I set connection strings, DI, and other configs) when my Azure function starts. So right now, it calls a Run meth

相关标签:
2条回答
  • 2020-12-18 00:29

    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.
         }
      }
    }
    
    0 讨论(0)
  • 2020-12-18 00:35

    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

    0 讨论(0)
提交回复
热议问题