Tuesday 15 June 2010

c# - Do DI Containers need to instantiate the object themselves in order to use constructor injection? -



c# - Do DI Containers need to instantiate the object themselves in order to use constructor injection? -

or instead of creating object themselves, somehow intercept or hook into object creation (for example, controller instantiated mvc framework) , pass in whatever dependencies they're required to?

i realize need do something when object created in order utilize constructor injection, unclear whether containers need creating, or if somehow intercept object's creation.

whatever reply is, di containers way?

i realize question obvious familiar tools structuremap, unity, ninject, etc... new them , realized don't know how work under covers. have scoured net , can't find answer.

in di/ioc containers i've used, containers creating themselves. won't find production code using new something(dependency1, dependency2)... instead, you'll have code implicitly or explicitly asking container "an instance of something" (maybe dependency of else). container takes care of either reusing instance of something, based on how it's configured (and how something annotated).

where do explicitly phone call constructor in test something, @ point container may not exist @ - or may have test-specific configuration allows inquire of dependencies in stock way, , maybe provide other dependencies in test-specific way. (in cases, still won't need phone call constructor explicitly... if have test configuration container, e.g. using false storage everything, may still need inquire instance of something utilize in tests.)

c# dependency-injection ioc-container

No comments:

Post a Comment