This project has moved and is read-only. For the latest updates, please go here.

Container Hierarchy: Generating elements the CompositionContainer does not remember.

Oct 27, 2011 at 5:17 PM

I just realize I killed myself in a hierarchy of composition containers - anyone has an advice hwot to solve this?

 I have an application consisting of three levels of element. One HOST, containing multiple (different) Services. Services expose Sessions. Services are singletons (implementing a subclass of service), sessions not.

The idea is that a session can be used to interact with a service through an API in a single threaded API. For example a MarketDataService may expose a RealTimeDataSession and a HistoricalDataSession with different API's.

Clients are supposed to get Sessions "somehow" from a central point but this central point is not supposed to control the lifetime. Sessions CAN include other sessions (for example a BacktestSession may internally need a HistoricalDataSession to get data.

Where I am stuck is this:

* Sessions are NonShared - every request shoud get a separate instance

* BUT: Right now thy do not dispose. It is a slow leak and it came up through a simple eror in db handling (A session has it's own composition container and I was not disposing this one, keeping database managers around that are hooked on this level).

Any idea how to rewrite it? Right now I see only this solution:

* Getting a new session is acall to GetSessionon the Host, but this does not result in a GetSession but in a new () + SatisfyImportsOnce - but it means when generating a session I have to manually get internal composed, which is a disadvantage.

* Somehow make sure that the sessions returned are not kept alive until the host disposes. I would prefer this - anyone an idea? Best would be if the Service would have it's own CompositioNContainer (it has) that can compose other services (it can not) and falls back to the central hsot level CompositionCotnainer for central objects. This would need a compose by factory, though, as the calls would have to generate new sessions.

I am open for any suggestion....