Azure 函数中的 Autofac 依赖注入 [英] Autofac Dependency Injection in Azure Function
本文介绍了Azure 函数中的 Autofac 依赖注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Azure 函数中使用 Autofac IOC 实现 DI.我需要构建容器,但不确定将代码放在哪里来构建容器
I am trying to implement DI using Autofac IOC in Azure function. I need to build the container, but not sure where to put the code to build the container
推荐答案
我认为现在你需要做一些丑陋的事情,比如:
I think for now you would need to do something ugly like:
public static string MyAwesomeFunction(string message)
{
if (MyService == null)
{
var instantiator = Initialize();
MyService = instantiator.Resolve<IService>();
}
return MyService.Hello(message);
}
private static IService MyService = null;
private static IContainer Initialize()
{
// Do your IoC magic here
}
这篇关于Azure 函数中的 Autofac 依赖注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文