What is best practise when instantiating a Castle Windsor container in a class library? [duplicate]
Asked Answered
B

2

5

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.

Bifoliolate answered 11/5, 2012 at 7:5 Comment(1)
Thanks guys great feedback, what you have mentioned makes a lot of sense, I can't even remember why I posted this question ;DBifoliolate
B
7

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.

Bakst answered 11/5, 2012 at 8:51 Comment(0)
C
6

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.

Cards answered 11/5, 2012 at 7:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.