[英]Time triggered Azure Functions
I have created a time triggered azure function to perform certain task, I'm using dependency injection to call Business layer method.But I'm bit confused and stuck how can I use the dependent reference variable inside Run method and call BL method as Run is static method.我创建了一个时间触发 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}");
}
}
As others have mentioned (putting it as an answer for visibility) removing the static method will allow you to make use of DI in your functions.正如其他人所提到的(将其作为可见性的答案)删除 static 方法将允许您在函数中使用 DI。 You should not need to make any other changes to the structure of the functions once you have setup the DI container and the function class's constructor to accept the injected services.
一旦设置了 DI 容器和 function 类的构造函数以接受注入的服务,就不需要对函数的结构进行任何其他更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.