开发者

Windsor: How do I tell the container to release DynamicParameters when releasing the component?

        windsorContainer.Register(
            Component.For<ClassWithReferenceToDisposableService>()
            .LifeStyle.Transient
            .DynamicParameters((k, d) =>
 开发者_JS百科                                                      {
                                                           d["disposableComponent"] =
                                                               windsorContainer.Resolve<DisposableComponent>();
                                                       }));


        windsorContainer.Register(Component.For<DisposableComponent>().LifeStyle.Transient);

        ClassWithReferenceToDisposableService service = windsorContainer.Resolve<ClassWithReferenceToDisposableService>();
        windsorContainer.Release(service);

When the container releases the service, is does not dispose of the "disposableComponent" due to the dynamic parameter. How can i opt in during creation and tell windsor to release the "disposableComponent" when releasing the service?


There's an overload to DynamicParameters that returns a delegate. This delegate is called when the component gets released and that's where you can release your dynamic parameters. See the documentation for an example.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜