簡體   English   中英

時間觸發 Azure 函數

[英]Time triggered Azure Functions

我創建了一個時間觸發 azure function 來執行某些任務,我正在使用依賴注入來調用業務層方法。但是我有點困惑並卡住了如何在 Run 方法中使用依賴引用變量並將 BL 方法調用為 Run是 static 方法。

public class FunctionAccount
{
    private IDeleteAccount _deleteAccount;
    public FunctionAccount(IDeleteAccount deleteAccount)
    {
        _deleteAccount = deleteAccount;
    }

     [FunctionName("FunctionDAccount")]
    public static void Run([TimerTrigger(GlobalConstant.DeleteAccountTimer)] TimerInfo myTimer)
    {
        _deleteAccount .DeletePastYearsUsers(); // This is what I want to do, but as Run method is static I'm not able to do so
        Log.Information($"Function executed at: {DateTime.Now}");
    }


}

正如其他人所提到的(將其作為可見性的答案)刪除 static 方法將允許您在函數中使用 DI。 一旦設置了 DI 容器和 function 類的構造函數以接受注入的服務,就不需要對函數的結構進行任何其他更改。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM