When you use dependency injection, the model shouldn't need to access the DI, since it is the DI that injects dependencies. The model objects should not be asking the DI container. When the your objects are asking the container for dependencies it is not called dependency injection, but service locator This is considered an anti-pattern and I agree.
The models would need access to the DI project since, for example, they'd need to request the database system from the DI System (Ninject) When you use dependency injection, the model shouldn't need to access the DI, since it is the DI that injects dependencies. The model objects should not be asking the DI container. When the your objects are asking the container for dependencies it is not called dependency injection, but service locator.
This is considered an anti-pattern, and I agree. My first thought was to create a seperate DI-project When you have a single application (i.e. A web app), the usual thing to do is completely configure the DI container in the end application, as close as possible to the application’s entry point.
This is called the Composition Root. All model projects need to use some sort of database system, so they all need access to yet another . Dll which implements all my database logic Try making POCO (plain old CLR objects) model/entity objects, or at least ensure that those objects don't need to reference any other project, which makes your architecture (and testing) much easier.
Use Ninject with the Register Resolve Release pattern from within a Composition Root.
The client application would use Ninject to inject the actual database and model implementations. The client application therefore needs to reference the database, idatabase, model and imodel projects. The idatabase and database projects need to reference the model project, as the methods will return model objects or collections of model objects.
Have a look at the repository pattern. Your model doesn't need to reference any of your projects.
Thanks for your answer! So I suppose the only way for my model to receive dependencies is by constructor injection, right? Because so far I've been using Ninject.kernel.
Get sometimes (Ninject being a singleton provider of the kernel) to create new sessions for my DB when needed, so sometimes a couple of times within the same method. In this particular case it wouldn't be an issue to just request sessions from the database object directly, but couldn't there be cases for which you'd need other DI methods than just constructor injection? – James Aug 1 at 13:31 1 If you are using POCOs (en.wikipedia.Org/wiki/Plain_Old_CLR_Object) you shouldn't need to inject anything into the model objects.
– Joe R Aug 1 at 13:34.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.