This question already has an answer here:
I am wondering where the best place to instantiate the castle Windsor container is in a class library.
Should I simply do it in the constructor of the class I am using or is there a single entry point for assemblies that I am unaware of?
Thanks.
The configuration of an injected object graph is entirely dependent on the needs of the application that actually uses it. The point of using the container is to be able to configure dependencies at runtime - a library doesn't know anything about how it's going to be used.
Library classes should be written in a way that allows you to use any container you like, or poor-man's-dependency-injection as the consumer sees fit. Coupling a library to a container is a smell.
I may say you should not use a container directly into your class library. Your class library should have dependecies between classes within the library. The application(Front-End / root of the apps graph) will use a container to resolve all dependencies including those into your class library.
IMHO using an IoC
within a class library smells like a ServiceLocator.
来源:https://stackoverflow.com/questions/10546920/what-is-best-practise-when-instantiating-a-castle-windsor-container-in-a-class-l