Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I thought of asking on SO, but it seems this is more of a "concept" type question than a "problem" type question. If it needs to be moved, please do so.

Anyway, I'm having a tough time finding straight info on this. I'm using Unity.Mvc3 to setup dependency injection for controllers and other components the controllers might use.

From what I understand from the Unity.Mvc3 website, anything that is IDisposable will be disposed at the end of the request from the container if it is registered with a HierarchicalLifetimeManager.

Does that mean that things registered with the ContainerControlledLifetimeManager will be registered as the same instance for all requests for as long as the server/application is running?

Can I register an instance using the HierarchicalLifetimeManager or does it have to be a type?

How do the application/session/request lifetimes work? I ask, because I come from PHP and PHP has no scope outside the request, so this is obviously something I need to get a hang of.

share|improve this question
    
In general, ASP.NET MVC (if done correctly) doesn't have scope outside the request either. The description on the Unity.MVC page says this; it "creates a child container per HTTP request and disposes of all registered IDisposable instances at the end of the request." –  Robert Harvey Feb 13 '13 at 22:28
    
@RobertHarvey The "(if done correctly)" part is what worries me. Are there some common pitfalls that one must be careful of, or is this question a bit too broad? –  Pinetree Feb 13 '13 at 22:50
    
The most common pitfalls are those that occur when treating ASP.NET MVC 3 like it is ASP.NET Webforms, where there is implied saving of state between requests. State is persisted, but it's not generally done in the Session object, or anywhere else but the data repository. Each request is a "transaction" in its own right; it starts when the request is made, and ends when the request is complete. –  Robert Harvey Feb 14 '13 at 0:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.