将 Autofac.Mvc5 从 3.3.2 更新到 3.3.3 后出错



将 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",并且似乎没有使用城堡项目中的DynamicProxy包装。此问题可能是由于 DynamicProxy 实现中的更改或使用不同的代理库来包装依赖项解析程序。

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

图像错误 https://i.stack.imgur.com/yJJXX.png 的网址

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

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

        // 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

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

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

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

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

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

我遇到了同样的问题。

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

可以通过使用 NuGet 包 MvcSiteMapProvider MVC5 Autofac 依赖项注入配置并设置自动fac(如本项目的自述文件中所述)来解决此问题。

我没有为我工作这一行:

 Autofac_RegisterApplicationModules(builder);

所以我改了这个:

  RegisterAssemblyModules(builder);

它现在有效。

感谢您的解决方案!

最新更新