I am testing a specific use-case for the Windsor ContainerWrapper which I would like to run past the forum.
The ContainerWrapper is a ComponentModel ServiceContainer - the essence of its purpose is to provide 'siting' functionality to components, a sited componed being one that has it's lifecycle managed (automatic disposal when the owner of the ServiceContainer is disposed), and provide services to the components directly within. I have a standard Windows Forms control hierarchy, where by I have replaced the default 'components' collection with a ContainerWrapper. These ContainerWrappers are chained through the control-hierarchy so that a deeply nested UserControl can obtain services from the Form simply by calling 'GetService'. Now, this works perfectly, I am just having a small issue with lifecycle management of services. Form ContainerWrapper1 UserControl1 ContainerWrapper2 UserControl2 TransientService | | | | | | [|] .ctor() | | | | | [|]---------->[|] .ctor() [|] | | | [|]-----------[|]-------------->[|] .ctor() | | | [|] [|] [|]-------------->[|] .ctor() [|] | [|] [|] [|]---------------[|]--------------->[|] | [|] [|] [|] [|] GetService [|] | [|] [|] [|] [|]<---------------[|] | [|] [|] GetService [|] [|] [|] | [|] [|]<--------------[|]---------------[|] [|] .ctor() | [|] [|]---------------[|]---------------[|]----------------[|]-------------- ->[|] [|] [|] [|] [|] [|] [|] [|] [|] [|] [|] [|] | [|] [|] [|] [|] | | [|] [|] [|] | | | [|] [|] | | | | [|] As in the diagram, the form creates the UserControl and sites it within the ContainerWrapper1, which in turn (InitializeComponent) creates UserControl2 and sites it within ContainerWrapper2. These wrappers are chained, but their Kernels are not (this is how the ContainerWrapper works internally). When UserControl2 asks for a service, which is configured at the ContainerWrapper1 level, the call gets promoted (NOT via the Kernel), from ContainerWrapper2 to ContainerWrapper1. UserControl2 now has a reference to a transient service. I have a case where by UserControl1 (and all its child controls) needs to be removed from Form.Controls collection, and disposed. This is fine, however ContainerWrapper1 holds the reference to the transient service (which is owned by the Form), so it is not disposed - even though the service was requested at the ContainerWrapper2 level.... Does this behaviour make sense? Or should (logically) ContainerWrapper2 be considered the 'owner' of the disposal policy of the service, and as such, dispose/release the transient instance? Thanks Adam Langley -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
