我有两堂课,其中一堂课被注入了另一堂课:-
public class A : IClassA
{
public A(IClassB b)
{
...
}
}
public class B : IClassB, IDisposable
{
...
}
它们的注册方式如下:-
container.Register(Component.For<IClassA>().ImplementedBy<A>().LifeStyle.Singleton);
container.Register(Component.For<IClassB>().ImplementedBy<B>().LifeStyle.Transient);
当我关闭应用程序时,我叫Container.Dispose()
。此时,我发现类“ B”的Dispose()
方法被调用了两次。如果我将类“ B”注册为 singleton ,那么它只会被调用一次。为什么会这样?
我正在使用温莎城堡v3.3.0。
如果有帮助,这里是两次Dispose()调用的调用堆栈(我在调用Container.Dispose()
时将其截断了)。
首次调用Dispose():
Castle.Windsor.dll!Castle.MicroKernel.LifecycleConcerns.DisposalConcern.Apply(Castle.Core.ComponentModel模型,对象组件)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyConcerns(System.Collections.Generic.IEnumerable步骤,对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyDecommissionConcerns(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalDestroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Destroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Release(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.DefaultHandler.ReleaseCore(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.AbstractHandler.Release(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Burden.Release()未知 Castle.Windsor.dll!Castle.MicroKernel.Releasers.LifecycledComponentsReleasePolicy.Dispose()未知 Castle.Windsor.dll!Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Dispose()未知 Castle.Windsor.dll!Castle.MicroKernel.LifecycleConcerns.DisposalConcern.Apply(Castle.Core.ComponentModel模型,对象组件)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyConcerns(System.Collections.Generic.IEnumerable步骤,对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyDecommissionConcerns(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalDestroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Destroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Release(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.DefaultHandler.ReleaseCore(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.AbstractHandler.Release(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Burden.Release()未知 Castle.Windsor.dll!Castle.MicroKernel.Releasers.LifecycledComponentsReleasePolicy.Dispose()未知 Castle.Windsor.dll!Castle.MicroKernel.DefaultKernel.DisposeComponentsInstancesWithinTracker()未知 Castle.Windsor.dll!Castle.MicroKernel.DefaultKernel.Dispose()未知 Castle.Windsor.dll!Castle.Windsor.WindsorContainer.Dispose()未知
第二次调用Dispose():
Castle.Windsor.dll!Castle.MicroKernel.LifecycleConcerns.DisposalConcern.Apply(Castle.Core.ComponentModel模型,对象组件)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyConcerns(System.Collections.Generic.IEnumerable步骤,对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.ApplyDecommissionConcerns(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalDestroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Destroy(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.Release(对象实例)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.DefaultHandler.ReleaseCore(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.AbstractHandler.Release(城堡.MicroKernel。负担)未知 Castle.Windsor.dll!Castle.MicroKernel.Burden.Release()未知 Castle.Windsor.dll!Castle.MicroKernel.Burden.Release.AnonymousMethod__0(Castle.MicroKernel.Burden c)未知 mscorlib.dll!System.Collections.Generic.List.ForEach(System.Action操作)未知 Castle.Windsor.dll!Castle.MicroKernel.Burden.Release()未知 Castle.Windsor.dll!Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Dispose()未知 Castle.Windsor.dll!Castle.MicroKernel.Handlers.DefaultHandler.Dispose()未知 Castle.Windsor.dll!Castle.MicroKernel.DefaultKernel.DisposeHandler(Castle.MicroKernel.IHandler处理程序)未知 Castle.Windsor.dll!Castle.MicroKernel.DefaultKernel.DisposeHandlers()未知 Castle.Windsor.dll!Castle.MicroKernel.DefaultKernel.Dispose()未知 Castle.Windsor.dll!Castle.Windsor.WindsorContainer.Dispose()未知