Dec 20, 2010 at 9:23 AM
Edited Dec 20, 2010 at 9:44 AM
Yes, lifetime manager.
I have created a kind of HierarchicalLifetimeManager which gets its value from a shared pool and returns to the pool when the child container is disposed. What I need to do now is equivalent to database connection pooling. My app always asks
for the same interface (say IMyConnection) but because the implementing MyConnection uses a connection string from another service IMyConnectionSettings this means I cannot simply return just any MyConnection from my pool.
So what I am thinking of doing is something like this
So the PooledLifetimeManager has an action which it can execute to get the key to the relevant pool by passing in the container.
I was thinking of adding a Configure when the PooledLifetimeExtension is registered, but not sure if that is the right approach or not seeing as I've not done it before. My code either uses the default pool, or uses alternate pools in a loop like so...
foreach(var dbInfo in DataConnectionInfos)
using(var childContainer = container.CreateChildContainer())
//Set the DB settings
var settings = new MyConnectionSettings();
settings.ConnectionString = dbInfo.ConnectionString;
//Resolve the command handler and execute it
var commandHandler = childContainer.Resolve<T>();
In this example the CommandHandler in question has a dependency to IMyConnection which is a pooled resource, but because this resource cannot have its ConnectionString altered once created I must retrieve a MyConnection from a specific pool keyed on ConnectionString.
I just threw lots of info at you there, I hope it was enough :-)