Very often, an Injection Dependency container is created for an ASP.NET application, so that it lives while the application is running.
I create a DI container in each request and release it at the end of the request.
The main goal is that any DI container supports the removal of objects when the container is deleted.
Optional: If I need to exchange resources between requests (NHibernate SessionFactory), I just save them in a static variable and encapsulate this value in the object per request. Like this:
public class SessionFactoryAggregator : ISessionFactory {
static ISessionFactory actualFactory;
}
This is just a simulated singleton pattern.
My questions:
- Can this be done?
- If not why and what should be done instead?
- Any known performance issues in this approach?
: Castle Windsor DI, .
.