使用Autofac在MVC中实现IOC

var builder = new ContainerBuilder();
//注册DispatchService类型到工厂中
builder.RegisterType<DispatchService>();
//通过工厂创建容器
using (var container = builder.Build())
{
//解析DispatchService并返回DispatchService实例
_dispatchService= container.Resolve<DispatchService>();
}

原文地址:https://www.cnblogs.com/hwisecn/p/5582861.html