1

Autofac 版本 2.3.2.632 中的 Autofac.Integration.Web.Mvc dll 有一个类 AutofacControllerFactory 定义为

 public class AutofacControllerFactory : DefaultControllerFactory
    {
        public AutofacControllerFactory(IContainerProvider containerProvider);

        protected override IController GetControllerInstance(RequestContext context, Type controllerType);
        public override void ReleaseController(IController controller);
    }

最新版本的 autofac (2.6.3.862) 没有 Autofac.Integration.Web.Mvc,而是有 Autofac.Integration.Mvc。但是这个 dll 没有 AutofacControllerFactory 类。dll Autofac.Integration.Mvc 有一个名为 AutofacDependencyResolver 的类,定义为

public class AutofacDependencyResolver : IDependencyResolver
{
    public AutofacDependencyResolver(ILifetimeScope container);
    public AutofacDependencyResolver(ILifetimeScope container, Action<ContainerBuilder> configurationAction);
    public AutofacDependencyResolver(ILifetimeScope container, ILifetimeScopeProvider lifetimeScopeProvider);
    public AutofacDependencyResolver(ILifetimeScope container, ILifetimeScopeProvider lifetimeScopeProvider, Action<ContainerBuilder> configurationAction);

    public ILifetimeScope ApplicationContainer { get; }
    public static AutofacDependencyResolver Current { get; }
    public ILifetimeScope RequestLifetimeScope { get; }

    public object GetService(Type serviceType);
    public IEnumerable<object> GetServices(Type serviceType);
}

最新版本的 Autofac 中 AutofacControllerFactory 的替代品是什么?

4

2 回答 2

2

没有替代品AutofacControllerFactory。相反,使用DependencyResolver.

Autofac wiki 有关于与更高版本的 ASP.NET MVC 集成的新方法的文档。该 wiki 页面包含指向示例应用程序的链接,您可以在其中查看实际工作代码。

于 2012-11-02T17:28:59.187 回答
1

我相信这是通过版本对 MVC API 的更改。在 MVC 3/4 中,相信您需要输入的Application_Start只是:

DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
于 2012-11-01T20:27:21.177 回答