Asp.net
Azure Functions 中的 DI
我在我的 ASP.NET Web API 應用程序中使用了一些類庫來處理我的所有後端內容,例如對 Azure SQL 數據庫、Cosmos DB 等多個數據庫的 CRUD 操作。
我不想重新發明輪子並能夠在我在 Visual Studio 2017 中創建的新 Azure Functions 中使用它們。我所有的儲存庫方法都使用一個介面。那麼,我將如何在我的新 Azure 函式中實現依賴注入?
我沒有看到對 DI 的任何支持,但我有點困惑。看起來 Azure Functions 與 WebJobs 基於相同的 SDK,我認為去年微軟已經開始在 WebJobs 中支持 DI - 我肯定知道,因為我使用 Ninject 實現了它。
有沒有辦法讓我可以在我的新 Azure Functions 項目中使用我現有的庫?
除了服務定位器(反)模式之外,我還看到了這兩種技術。我也詢問了 Azure Functions 團隊的意見。
<https://blog.wille-zone.de/post/azure-functions-dependency-injection/>
<https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/>