My application has a child container per request, this is because there are a lot of services used in each request which depend upon an IUnitOfWork. I thought it would be nice if I could define a pool of these IUnitOfWork instances so that any cost involved in creating them is reduced, they can just be reused in a round-robin fashion. Well, more accurately, the object space (EcoSpace) on which they depend can anyway. A pool can now be registered like so… 1 //Must be called once, when the container is created
2 container.AddNewExtension<PooledLifetimeExtension>();
3 //To register a pooled item
4...
I was making some speed improvements to my current ASP MVC application. One of the things I did was to change from creating a completely new IUnityContainer for each request over to creating one master (template) container with all the services registered with HierarchicalLifetimeManager. Then whenever a controller is required my ControllerFactory does this 1 if (controllerType == null)
2 return null;
3 var requestContainer = Container.CreateChildContainer();
4 return (IController) requestContainer.Resolve(controllerType);
That’s all nice and simple, however it causes a memory leak. The reason is that the parent container holds a reference to all of its children. The only way to...