错误的循环依赖异常 - 以快速顺序解析组件

时间:2014-10-29 16:02:37

标签: c# .net exception dependency-injection castle-windsor

我正在使用工厂来解决Castle Windsor中的组件(带参数)并且它正常工作正常。但是,(瞬态)实例创建与传入事件相关联,如果事件间间隔太短,则会得到循环依赖性异常。

  • 为什么?我不应该基于以下观察得到这个异常:相同的工厂方法正常工作并且我认为不相信任何实际的循环依赖。

当计时太近/对象创建太快

这是显示详细信息的日志,请注意这两个调用的时间非常接近(需要)。

IProcessChanger CreateProcessChanger(int pid) 10472 @ 15:36:31.667
IProcessChanger CreateProcessChanger(int pid) 5700 @ 15:36:31.700
First Chance Exception in xxx.vshost.exe, sender Name:xxx.vshost.exe
There are no context policies.
! CircularDependencyException: Dependency cycle has been detected when trying to resolve component 'xxx.ProcessChanger'.
The resolution tree that resulted in the cycle is the following:
Component 'xxx.ProcessChanger' resolved as dependency of
    component 'xxx.ProcessChanger' which is the root component being resolved.
 @ 15:36:31.948
A first chance exception of type 'Castle.MicroKernel.CircularDependencyException' occurred in Castle.Windsor.dll
Unhandled Exception! CircularDependencyException: Dependency cycle has been detected when trying to resolve component 'xxx.ProcessChanger'.
The resolution tree that resulted in the cycle is the following:
Component 'xxx.ProcessChanger' resolved as dependency of
    component 'xxx.ProcessChanger' which is the root component being resolved.
 @ 15:36:32.013
   at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, Burden& burden)
   at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired)
   at Castle.MicroKernel.Handlers.AbstractHandler.Resolve(CreationContext context)
   at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
   at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments)
   at Castle.Windsor.WindsorContainer.Resolve[T](IDictionary arguments)
   at xxx.BaseFactory.Create[T](Object[] arguments) ...
The program '[9116] xxx.vshost.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.
  • 如何解决?

0 个答案:

没有答案