简体   繁体   English

时间触发 Azure 函数

[英]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.

相关问题 结合了队列触发函数和计划触发函数的 Azure WebJobs - Azure WebJobs that combine queue triggered functions and Scheduled triggered functions 队列触发的等待时间 Azure 函数与等效的 Webjobs 相比非常长 - Wait time for queue-triggered Azure Functions is very high compared to equivalent Webjobs 连续 Azure 具有 Http 触发函数的 WebJob - Continuous Azure WebJob with Http Triggered Functions 具有定时器触发的 Azure 功能的令牌缓存 - Token Cache with Timer-Triggered Azure Functions Azure Functions – 时间触发器 - Azure Functions – Time Trigger 对时间触发的 Azure 函数进行单元测试 - Unit Test a Time Triggered Azure Function 一个 eventhub 是否可以触发 2 个 azure 函数? - Is it possible that 2 azure functions can get triggered by one eventhub? 如何管理并发 Http 触发的 Azure 函数的数据? - How to manage data on concurrent Http Triggered Azure Functions? 如何执行Azure Queue触发的大量持久函数? - How to execute a lot of durable functions triggered by Azure Queue? 计时器触发的Azure功能未在计划的时间触发,并且因Azure存储超时异常而失败 - Timer-triggered Azure Function not triggered on scheduled time and failed with Azure storage timeout exception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM