【问题标题】:Error after update Autofac.Mvc5 from 3.3.2 to 3.3.3将 Autofac.Mvc5 从 3.3.2 更新到 3.3.3 后出错
【发布时间】:2015-08-26 12:21:09
【问题描述】:

将 Autofac.Mvc5 从 3.3.2 更新到 3.3.3 后出现错误 我将我的问题发布到 github https://github.com/autofac/Autofac/issues/572#issuecomment-63236738 并得到了我需要在这里询问的回复 :)

下面我的情况:

我有什么:

// Setup DI as default MVC controller factory
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

我需要在自定义成员资格提供程序的注入属性中使用它

protected IMembershipService MembershipService
{
    get
    {
         return DependencyResolver.Current.GetService();
    }
}

问题:依赖解析器的类型不是“Autofac.Integration.Mvc.AutofacDependencyResolver”

请帮我解决这个问题。

更新 所以现在我从 3.3.2 更新到

依赖解析器不是“Autofac.Integration.Mvc.AutofacDependencyResolver”类型,并且似乎没有使用 Castle Project 中的 DynamicProxy 进行包装。此问题可能是由于 DynamicProxy 实现发生更改或使用不同的代理库来包装依赖关系解析器造成的。

关于如何解决这个问题的任何想法?

图片网址错误http://i.stack.imgur.com/yJJXX.png

更新 这是我发现的 github.com/autofac/Autofac/blob/82cc138596e74095f50720319feb2a2ce734310d/Core/Source/Autofac.Integration.Mvc/AutofacDependencyResolver.cs 在这个文件中,我们有部分为此类文本引发异常。 这只是所有源代码中的一部分,所以我认为我需要继续前进并找出我遇到这个问题的原因。此外,我的代码何时以及为何请求此方法 AutofacDependencyResolver.Current。 当我检查我没有直接调用 AutofacDependencyResolver.Current 时。 我需要调查调用的其他变体(地点)。

【问题讨论】:

  • 但是你的问题是什么?
  • 我的问题:依赖解析器不是“Autofac.Integration.Mvc.AutofacDependencyResolver”类型的
  • 关于如何解决这个问题的任何想法?
  • 查看堆栈跟踪,它似乎与您的会员服务无关 - 它来自过滤器提供商。请更新您的问题:您正在使用的软件包/版本列表(不仅仅是 Autofac - 一切);您的应用程序启动代码(全部);您为排除故障而采取的步骤;以及任何其他可能对人们有所帮助的信息。也许是 GitHub 上的复制品?不幸的是,这里不足以帮助您诊断问题。
  • 嗨,特拉维斯,非常感谢。

标签: c# asp.net-mvc dependency-injection autofac custom-membershipprovider


【解决方案1】:

现在我看到了这样的分辨率

        // Create DI container
        var builder = new ContainerBuilder();

        // Register application modules
        Autofac_RegisterApplicationModules(builder);

        // Register filter provider
        //builder.RegisterFilterProvider();

        // Register MVC specific abstractions (HttpRequestBase,HttpResponceBase etc)
        builder.RegisterModule(new AutofacWebTypesModule());

        // container
        var container = builder.Build();

如你所见,我评论了这一行

//builder.RegisterFilterProvider();

但如果可以,我需要确认!

请谁知道解释它是否正确和/或如何正确。

跟踪结果如下 - 需要帮助

[InvalidOperationException: 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.]
   Autofac.Integration.Mvc.AutofacDependencyResolver.get_Current() +367
   Autofac.Integration.Mvc.AutofacFilterProvider.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +196
   System.Web.Mvc.FilterProviderCollection.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +279
   System.Web.Mvc.ControllerActionInvoker.GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +62
   System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) +436
   System.Web.Mvc.Controller.<BeginExecuteCore>b__1c(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) +82
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +105
   System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) +588
   System.Web.Mvc.Controller.<BeginExecute>b__14(AsyncCallback asyncCallback, Object callbackState, Controller controller) +47
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +65
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +139
   System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +484
   System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) +50
   System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__4(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) +98
   System.Web.Mvc.Async.WrappedAsyncVoid`1.CallBeginDelegate(AsyncCallback callback, Object callbackState) +73
   System.Web.Mvc.Async.WrappedAsyncResultBase`1.Begin(AsyncCallback callback, Object state, Int32 timeout) +151
   System.Web.Mvc.Async.AsyncResultWrapper.Begin(AsyncCallback callback, Object callbackState, BeginInvokeDelegate`1 beginDelegate, EndInvokeVoidDelegate`1 endDelegate, TState invokeState, Object tag, Int32 timeout, SynchronizationContext callbackSyncContext) +106
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) +446
   System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state) +88
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData) +50
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +301
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

经过我的新调查,我发现了这个问题。 我的网站使用 MVCSiteMap

http://i.stack.imgur.com/7xnul.png

我现在正在检查如何配置 MvcSiteMapProvider 以不更改 DI。

<add key="MvcSiteMapProvider_UseExternalDIContainer" value="false" />

所以我认为我需要将其更改为 true 以解决问题。 我现在正在进行中,很快就会通知您。

如果您有解决方案,请随时更新我的​​观点!

【讨论】:

  • 我也遇到了这个问题,但我不明白修复方法。如果我们停止注册过滤器提供程序,这不会导致依赖于这些提供程序的代码出现问题吗?
  • 我在下面添加了新的答案,请检查一下。
【解决方案2】:

我遇到了同样的问题。

这是由于 MvcSiteMapProvider 使用了它自己的 DI。

您可以通过使用 NuGet 包 MvcSiteMapProvider MVC5 Autofac Dependency Injection Configuration 并按照此项目的自述文件中的说明设置 Autofac 来解决此问题。

【讨论】:

    【解决方案3】:

    这条线我没有为我工作:

     Autofac_RegisterApplicationModules(builder);
    

    所以我改变了它:

      RegisterAssemblyModules(builder);
    

    现在可以使用了。

    感谢您的解决方案!

    【讨论】:

    • Autofac_RegisterApplicationModules(builder);只是我注册 autofac 模块和 RegisterAssemblyModules(builder) 的方法;在那里。我认为你的问题是因为你没有请求 RegisterAssemblyModules(builder);。所以这与我的问题无关。
    猜你喜欢
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2020-09-13
    • 2013-08-13
    • 2017-04-13
    • 1970-01-01
    • 2023-03-14
    相关资源
    最近更新 更多