Reputation: 13340
I have all sorts of different models and many of them have at least one dependency (usually a Db adapter). I am just now getting into the idea of DIC or IoC, and I'm trying to wrap my head around what is needed - all the examples typically show the simple creation of a single object with a container.
If I have many user models, many blog models, and all sorts of others, how do I manage this? Is it common to have 1 large container, many different smaller ones, or even a single factory PER model?
Or am I already thinking about this incorrectly?
NOTE: As asked below, by model, I believe I mean "domain model". To be more specific - the classes that help me manage the data that is specific to my website/application, like Users, Blogs, etc.
Upvotes: 1
Views: 144
Reputation: 6806
One container for your application is usually sufficient. There is a concept called Composition Root that describes how to use a DI container properly.
Business model classes like Users, Blogs etc. are usually not pulled from the container. You provide designated factories which in turn can be injected into those classes that need to create your model objects.
Upvotes: 3