views:

68

answers:

1

Hi folks,

I'm playing around with some Dependency Injection (StructureMap) with my ASP.NET MVC application. Works great.

Becuase StructureMap is using DI via the most gready constructor (I hope I got that concept named right), I'm under the impression that it creates an instance of an object for each argument, in the most gready constructor.

So, is it possible to tell a DI framework (in this case, it's StructureMap but i'm curious if it can do it for any other .NET DI Framework) to NOT create the instance when the constructor is called, but to delay that object's construction until required?

Sorta like some lazy-object construction or something...

+1  A: 

All di frameworks that support singleton->session/request scoped mappings typically instantiate a proxy object instead of the "real" object when a singleton object needs to access a session scoped object. Construction of the "real" instance is normally deferred to the first time a method on the proxy is invoked.

I believe castle windsor supports this mechanism.

krosenvold