检测到双向依赖关系

时间:2017-06-09 05:35:32

标签: c# asp.net-mvc model-view-controller

好的,我收到了一个堆栈错误。它被抓住的文件在这里

Server Error in '/' Application.

Bi-directional dependency relationship detected!
Check the StructureMap stacktrace below:
1.) Lambda: default
2.) Instance of NHibernate.ISession
3.) Container.GetInstance(NHibernate.ISession)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: StructureMap.Building.StructureMapBuildException: Bi-directional dependency relationship detected!
Check the StructureMap stacktrace below:
1.) Lambda: default
2.) Instance of NHibernate.ISession
3.) Container.GetInstance(NHibernate.ISession)


Source Error: 


Line 43:         {
Line 44:             var container = StructuremapMvc.StructureMapDependencyScope.CurrentNestedContainer;
Line 45:             return container.GetInstance<ISession>();
Line 46:         }
Line 47: 

Source File: C:\projects\NicholsFarms_demo_newCropYear\Nichols\src\Nichols.Web\DependencyResolution\StructureMapScopeModule.cs    Line: 45 

Stack Trace: 


[StructureMapBuildException: Bi-directional dependency relationship detected!
Check the StructureMap stacktrace below:
1.) Lambda: default
2.) Instance of NHibernate.ISession
3.) Container.GetInstance(NHibernate.ISession)
]
   lambda_method(Closure , IBuildSession , IContext ) +692
   StructureMap.Building.BuildPlan.Build(IBuildSession session, IContext context) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Building\BuildPlan.cs:151
   StructureMap.Pipeline.LifecycleObjectCache.Get(Type pluginType, Instance instance, IBuildSession session) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Pipeline\LifecycleObjectCache.cs:71
   StructureMap.SessionCache.GetObject(Type pluginType, Instance instance, ILifecycle lifecycle) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\SessionCache.cs:88
   StructureMap.SessionCache.GetDefault(Type pluginType, IPipelineGraph pipelineGraph) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\SessionCache.cs:66
   StructureMap.Container.GetInstance(Type pluginType) in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Container.cs:335
   StructureMap.Container.GetInstance() in c:\BuildAgent\work\996e173a8ceccdca\src\StructureMap\Container.cs:200
   Nichols.Web.DependencyResolution.StructureMapScopeModule.GetCurrentSession() in C:\projects\NicholsFarms_demo_newCropYear\Nichols\src\Nichols.Web\DependencyResolution\StructureMapScopeModule.cs:45
   Nichols.Web.DependencyResolution.StructureMapScopeModule.<Init>b__1_0(Object sender, EventArgs e) in C:\projects\NicholsFarms_demo_newCropYear\Nichols\src\Nichols.Web\DependencyResolution\StructureMapScopeModule.cs:20
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +142
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +92

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.1055.0

我到处寻找,它引用版本3.0.5作为可能的解决方案。任何帮助表示赞赏!

我收到的错误是:

id, start_date,end_date
1,2016-03-23,2016-07-18
2,2016-01-01,2016-01-02
3,2016-10-05,2016-11-05
4,2016-01-01,2016-12-31

3 个答案:

答案 0 :(得分:1)

为了避免双向依赖关系异常,您可以实现延迟加载,如下所示。

    private readonly Lazy<IService> _service;

    public MainService(Lazy<IService> service)
   {
     _service=service;
   }

您现在可以将服务中的方法称为

_service.Value.Method()

我认为这应该可以解决你的问题

答案 1 :(得分:0)

我们也面临着同样的问题,将StructureMap nuget软件包更新到3.1.5版本已经解决了我们的问题。

答案 2 :(得分:0)

在我的情况下,有一种依赖关系是未从API加载实现。

API上安装的Newtownsoft版本低于实现,因此,当尝试加载该版本时,它失败了。错误确实令人误解。我必须在实现上评论字段和构造函数,然后显示真正的错误。然后只需更新Newtosoft即可修复所有问题。

相关问题