views:

84

answers:

1

What should I be careful about when building a class library complex enough to use internal dependency injection?

Assuming that it will use Castle Windsor (as an example), what would be the best place/method to configure the container, given that the library will be used by simple console application (with no DI), web forms using the same container (Castle Windsor), and web apps using a different container (NInject)?

+2  A: 

I would use the facade pattern here: in the library, expose a public method on a public class that does the container initialization (such as a simple Initialize()), and use Castle Windsor only internally within the library, so that the library clients don't even know that you are using it.

Konamiman
+1 Given the requirements set forth in the OP, the Facade pattern sounds like a good fit. However, I would question whether the decision to hide a DI Container as an implementation detail is wise, but I guess it depends...
Mark Seemann
It's a good start, thank you. Also, I could also use Initialize() to pass the required runtime configuration values packed in an object by Castle DictionaryAdapter or something similar, depending on the calling application.
alexandrul