开发者

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

开发者 https://www.devze.com 2023-01-02 19:45 出处:网络
windsorContainer.Register( Component.For<ClassWithReferenceToDisposableService>() .LifeStyle.Transient
        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

精彩评论

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