.netcastle-windsornservicebus3

Snapshots with Castle Windsor child containers


After reading the page (http://docs.particular.net/nservicebus/containers/child-containers) regarding support for child containers by NServiceBus 3, I was expecting that in Castle Windsor transient components in the parent container behave like singletons for the child container. However dependencies of those parent components from the child containers are instantiated every time.

Is there a way to achieve this behavior of parent container snapshots in Castle Windsor? In other words, transient for component in the container, singleton if resolved from a child container.


Solution

  • NServiceBus uses the Scoped lifestyle functionality in Castle Windsor to implement child container functionality, read about scoped lifestyle here: http://docs.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx. So transients will behave like transients singletons will behave like singletons and scoped will behave like singleton pr nservicebus request. We use the scoped lifestyle for our ISession and singleton for 99% of the rest. I seldomly need transients, at least when doing web-apps. Why do you want a components to behave differently based on where its being resolved from? I am quite sure you can accomplish this in another way.