Possible Duplicate:
What should be injected as C'tor paramter under DI principles ?
I looking into using Castle Windsor for my next project and I trying to understand what objects should go into a dependency container. My initial thoughts were if an object accessed an exernal resource, email server, database, file system, etc, then that is a good candidate for going into the container. But, then I thought that any object that makes “use” of an external resource should also go into the container as well.
Would this be a valid approach to take when working with a dependency container?
a dependency injection container is an objects that holds implementations of certain types (mainly implementing a certain interface or base class), which are used to
Resolvethe dependencies of an object.There are 3 phases for using a DIC: you have objects that have some “dependencies” (preferably on Interfaces) which they declare either through a constructor (ex: using the
InjectionConstructorAttributein Unity) or property (ex: using theDependencyAttributein Unity); The next step is registering implementations for those dependencies, and this can be achieved via code or a configuration file, ex (unity):the third phase is actually resolving a certain type from the container, which resolves it’s dependencies (and their dependencies if they have any, and so on), ex. (unity):
So, in answer to your question, what should go into the dependency injection container is any type that’s necessary for resolving other types, or any type that has dependencies of its own (which have to be registered with the container at some point).
I hope this helps 🙂