Windsor:如何在释放组件时告诉容器释放DynamicParameters?

时间:2010-06-04 11:43:15

标签: castle-windsor

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


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

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

当容器释放服务时,由于动态参数,不会丢弃“disposableComponent”。如何在创建过程中选择加入并告诉windsor在发布服务时释放“disposableComponent”?

1 个答案:

答案 0 :(得分:1)

DynamicParameters的重载会返回委托。当组件被释放时,将调用此委托,您可以在此处释放动态参数。有关示例,请参阅the documentation