views:

8

answers:

1
        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);

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?

+1  A: 

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.

Krzysztof Koźmic

related questions