开发者

When does Windsor Container trigger IKernel.ComponentDestroyed event for transient components?

The event is not triggered when container.Release is called, the following test always fails:

public void ComponentDestroyedEvent()
{
  var wasDestroyed = false;

  var container = new WindsorContainer()
    .Register(
      Component.For(typeof (Cat))
        .LifeStyle.Transient
        .O开发者_如何学PythonnCreate((k, instance) => {
          k.ComponentDestroyed += (model, component) => {
            if (component == instance)
              wasDestroyed = true;
          };
        }));


  var cat = container.Resolve<Cat>();
  container.Release(cat);

  Assert.True(wasDestroyed);
}

When is ComponentDestroyed event triggered?


Mauricio is right - the event is not triggered for this component, because the component is not tracked and Windsor wouldn't have anything to do with it anyway.

In case when a component is tracked the event is raised as the last step of the pipeline, after all decommission steps were ran.

Windsor 3, when it comes out, has a OnDestroy method which takes a lambda and adds a decommission step thus forcing the component to be tracked, which means the code you put in there will be called upon release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜