Earlier, we serve with web service but we decide to use dll methods. Because served products are on same machine with common database. So we start to create a library with .net core. This library will be used by seperate .net applications/projects. Should we use/need dependency injection? Application itself will be have its own ui but it is not huge ui. Important part for us is serving with .dll to other projects. We don't acquire enough knowledge so decide to asking here.

  • 1
    I think we need some more information. A) At a high level, what is this library doing? Is it data access? Logging? Business logic? B) What kind of behavior do you want to inject into this library? C) Are you adhering to any well know architectural patterns, like Onion Architecture, Clean Architecture, Hexagonal Architecture, etc? D) Will projects outside your organization be using this library, or just inside? Jan 23, 2020 at 12:50

1 Answer 1


In general DI should be supported in libraries. The actual implementation or selection of a DI Container should not be done by a library, that should be left to the root application.

That way the root application can decide on

  • whether or not to use DI
  • what DI library to use
  • which other dependencies to load/pass on to the library

DI support can be implemented by providing proper interfaces and constructors that take these interfaces to receive their dependencies.

  • 1
    What does "DI should be supported but not implemented in libraries" mean in practice? Because if you "[provide] proper interfaces and constructors that take these interfaces to receive their dependencies", then you've implemented DI within the library.
    – David Arno
    Jan 23, 2020 at 14:04
  • 1
    @DavidArno - Sorry I meant the implementation or use of a container. I'll adjust my answer
    – Emond
    Jan 23, 2020 at 14:14
  • 2
    Just to clarify, dependency injection is just a concept, which is not tied to container frameworks. It seems that your definition of "implementation" is "a dependency injection framework", but that's a bit misleading to me. Jan 23, 2020 at 14:19
  • 2
    @VincentSavard - I agree. The problem is that as soon as we talk about "use dependency injection" (OP) it is not clear what is exactly meant. Not creating instances but only accepting implementation dependencies through interfaces in constructors might cover that but I suspect that most developers might be thinking about using a container. My point is that a library should not be dependent on a particular container but leave that to the root.
    – Emond
    Jan 23, 2020 at 14:28
  • @Erno I'm aware you want to help, but the OP wasn't clear on what he needs and we shouldn't try to answer unclear questions.
    – T. Sar
    Jan 24, 2020 at 12:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.