What are the best practices for class libraries using dependency injection for internal operations?

What should I be careful about when building a complex library of classes sufficient to use internal dependency injection?

Assuming he would use Castle Windsor (as an example), which would be the best place / method to configure the container, given that the library would be used by a simple console application (without DI), web forms using the same container (Castle Windsor ) and web applications using a different container (NInject)?

+6
c # dependency-injection inversion-of-control
source share
2 answers

I used the facade template here: in the library, output the public method to an open class that initializes the container (for example, a simple Initialize() ) and use Castle Windsor only inside the library, so the library clients do not even know that you are using it.

+6
source share

Not that the answer didn't work, but I think anyone who lands here should take a look at this Q / A. After reading this, I MUST agree that using an IoC within a class library smells like a ServiceLocator (anti-pattern) and Coupling a library to a container is a smell .

At first, I thought that I would do something good, it was best to see it first.

+2
source share

All Articles