Azure Function ServiceBus 触发依赖注入
Azure Function ServiceBus Trigger Dependency Injection
我一直在尝试为 Azure Functions 实现 DI,其中函数由 ServiceBus 触发(topics/subscriptions 在这种情况下):
[Singleton]
[FunctionName("Alert")]
public static async Task Alert([ServiceBusTrigger(Topic.Alert, Subscription.PowerBi, Connection = "servicebusconnectionstring")] Message message, [Inject]IPowerBiService powerBiService, [Inject]IQueueService queueService)
我在以下站点上阅读了有关 Azure Functions 和 DI 的信息:
- https://mcguirev10.com/2018/04/03/service-locator-azure-functions-v2.html
- https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
- https://github.com/introtocomputerscience/azure-function-autofac-dependency-injection
所有示例都使用 HTTP 触发器运行,我假设 IIS 主机已启动并且 运行 并且包含服务。但是使用 ServiceBus 触发器,我无法让它工作。我已经实施了上述解决方案,还有一些解决方案,但都遇到了同样的问题。代码有效,但服务是为 message/trigger 创建的。
有没有人设法做到这一点,或者不可能做到?
注意(更新):
我得到了一些我还没有时间验证的更多信息,但我一直在为我的 Azure Functions 使用消费计划。您可能需要一个应用程序服务计划(使用消费,因为该价格模型更方便)。如果有人对此了解更多?
我将在本周晚些时候对此进行调查。
我只是想确认它现在使用应用服务计划而不是消费计划可以正常工作。不同之处在于 "cold start" 而不是 "warm" 主机。
我想所有不同的 DI 实现都应该可以正常工作。
我一直在使用以下内容:https://github.com/MV10/Azure.FunctionsV2.Service.Locator
我一直在尝试为 Azure Functions 实现 DI,其中函数由 ServiceBus 触发(topics/subscriptions 在这种情况下):
[Singleton]
[FunctionName("Alert")]
public static async Task Alert([ServiceBusTrigger(Topic.Alert, Subscription.PowerBi, Connection = "servicebusconnectionstring")] Message message, [Inject]IPowerBiService powerBiService, [Inject]IQueueService queueService)
我在以下站点上阅读了有关 Azure Functions 和 DI 的信息:
- https://mcguirev10.com/2018/04/03/service-locator-azure-functions-v2.html
- https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
- https://github.com/introtocomputerscience/azure-function-autofac-dependency-injection
所有示例都使用 HTTP 触发器运行,我假设 IIS 主机已启动并且 运行 并且包含服务。但是使用 ServiceBus 触发器,我无法让它工作。我已经实施了上述解决方案,还有一些解决方案,但都遇到了同样的问题。代码有效,但服务是为 message/trigger 创建的。
有没有人设法做到这一点,或者不可能做到?
注意(更新): 我得到了一些我还没有时间验证的更多信息,但我一直在为我的 Azure Functions 使用消费计划。您可能需要一个应用程序服务计划(使用消费,因为该价格模型更方便)。如果有人对此了解更多? 我将在本周晚些时候对此进行调查。
我只是想确认它现在使用应用服务计划而不是消费计划可以正常工作。不同之处在于 "cold start" 而不是 "warm" 主机。
我想所有不同的 DI 实现都应该可以正常工作。 我一直在使用以下内容:https://github.com/MV10/Azure.FunctionsV2.Service.Locator