Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Dependency Injection tends to use a concept known as a composition root. This is a single place in your application where the composition of the object graphs for your application take place.</p> <p>You do not use a dependency injection container in a library, per se. Your library may include objects that can be injected, but it tends to be an application based tool, not a library based tool.</p> <p>What this means is that if you are creating a library only, you would not use a dependency injection container in it, or configure a container in it. Instead, you would create your library to work with dependency injection from your application. In your case, you would simply design your Repository, Unit of Work, etc.. to accept its dependencies via constructor injection. Then, in your application that uses your library you would use a DI container (such as Ninject) to configure how objects get created.</p> <p>This does a number of things. First, it allows the application to control how objects are created. For instance, if you're using your library in a web app, then you can configure it to create an instance of your repository that lives for the life of one request. If your library did this, then you would have no control over this at the application level.</p> <p>Second, if you use a DI container in your library, then you would also need a DI container in your app, thus you would end up with two DI containers, and that could cause various conflicts. There should only be one DI container in an application in most cases.</p> <p>Finally, you are committing a classic newbie blunder. You are confusing the DI container, with the concepts of DI itself. DI is the way in which you design your classes, in particular how they accept dependencies from outside the objects.</p> <p>A DI Container is a tool used to achieve DI, not DI in and of itself.</p> <p>TL;DR</p> <p>Do not design libraries to have their own DI container. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload