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屋!
查看全文