Dependency Injection

I am very new to this, so bear with me.

I have an MVC application using the Service / Repository / EF4 template and I'm trying to use Ninject. I work on controllers, they are a constructor that introduces services, but services are a constructor that repositories are built into, and I'm not sure where to process it.

I'm trying to make every layer only know about the bottom layer, is this true? If so, the MVC application only knows about the service level, and the service level knows only about the repository layer, etc. So in my Ninject module, where I create the bindings, I cannot say:

Bind(Of IRepository(Of Category)).To(Of EFRepository(Of Category))

Where do I handle the injection in?

+5
source share
1 answer

The comments on your question do provide some useful information.

I usually arrange things like this to accomplish what you are talking about - this is only part of it that applies directly to dependency injection:

  • I installed a Visual Studio solution to create one project / assembly per layer in the application. Having it this way, you must set the link from one project to another layer in order to be able to call this layer. So, for example, you configured the link from the MVC application level to the service level, but not from the MVC application to the repository level to prevent the MVC application from accessing the repository level.
  • , , , -, "Impl", - ; "", , (), .
  • / NInject, .
  • (. Mark Seeman: Ninject 2+ ( ?)), , .
  • , , ( [Inject], , ).
+7

All Articles