在autofac中注册过滤器时出错(RegisterFilterProvider)

时间:2015-02-21 10:15:12

标签: c# asp.net-mvc-5 autofac

使用RegisterFilterProvider时 我收到这个错误:

The dependency resolver is not of type  
    'Autofac.Integration.Mvc.AutofacDependencyResolver'   
    and does not appear to be wrapped using DynamicProxy from the Castle Project.   
    This issue could be the result of a change in the DynamicProxy    
    implementation or the use of a different proxy library to  
    wrap the dependency resolver.

我的注册码看起来像这样。

        var builder = new ContainerBuilder();

        builder.RegisterType<MethodCallLoggingInterceptor>().AsSelf();
        builder.RegisterModule<SiteModule>();
        builder.RegisterModule<ValidationModule>();
        builder.RegisterModule<JobModule>();
        builder.RegisterControllers(typeof(MvcApplication).Assembly);
        builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
        builder.RegisterApiControllers(typeof(MvcApplication).Assembly);
        builder.RegisterModule(new AutofacWebTypesModule());

        builder.RegisterType<DataContext>()
            .As<IRepository>()
            .As<DbContext>()
            .InstancePerLifetimeScope();

        builder.RegisterType<LoginUserManager>().AsSelf().AsImplementedInterfaces();
        builder.RegisterType<LoginUserStore>().AsImplementedInterfaces();
        builder.RegisterType<AccessController>().As<IAccessController>();
        builder.RegisterType<SelectListBinder>().As<ISelectListBinder>();

        builder.RegisterType<UserCache>().As<IUserCache>();
        builder.RegisterType<CacheManager>().As<ICacheManager>();
        builder.RegisterType<HttpCacheEngine>().As<ICacheEngine>();
        builder.RegisterType<TenantLogger>().As<ILogger>().WithParameter("category", "Aureus");
        builder.RegisterType<PerformanceLogger>().As<IPerformanceLogger>().WithParameter("category", "Performance");

        builder.RegisterModelBinders(typeof(MvcApplication).Assembly);
        builder.RegisterModelBinderProvider();

        // THIS IS THE LINE OF CODE WITH THE PROBLEM
        builder.RegisterFilterProvider();

        var container = builder.Build();
        System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

我的autofac版本

Autofac                        3.5.2
Autofac.Extras.DynamicProxy2   3.0.5
Autofac.Mvc5                   3.3.3
Autofac.WebApi2                3.4.0                
AutofacContrib.NSubstitute     3.3.2
Microsoft.AspNet.Mvc           5.2.3
Microsoft.AspNet.Mvc.Futures   5.0.0
Microsoft.AspNet.Razor         3.2.3

0 个答案:

没有答案