Is there a 'Release' method?

Nov 29, 2012 at 11:39 AM


This might a dumb question, but is there a release method (RRR pattern) that would deconstruct the dependency tree (incl. disposing disposable objects ect..) ?


Nov 29, 2012 at 4:41 PM
Edited Dec 10, 2012 at 11:04 PM

Great question! There is no release method. Simple Injector does not hold on to objects. Objects are not tracked and not disposed. This behavior is chosen because it is the easiest to work with and leads to the least surprises.

Exceptions to the rule are the RegisterPerWebRequest, RegisterPerLifetimeScope and RegisterPerWcfOperation extension methods (available as integration packages). But even with these methods, there is no 'release'. Lifetime Scoped objects are released after you dispose the explicitly created scope. Web Request and WCF operation objects are disposed when the web request and WCF operation ends. This is done for you under the covers. Again, no need to call a release method.

The registeration methods for these lifestyles allow overriding the default behavior and suppress disposing objects. And they offer a way to register services with another lifetime (such as transient) to be disposed when the scope or request ends.

In other words, these lifestyles implement the RRR pattern implicitly, without needing any explicit action from the user.

Marked as answer by dot_NET_Junkie on 11/4/2013 at 2:03 AM