views:

56

answers:

1

How do I tell castle to pick up an interface implementation from the assemblies in the executing directory.
E.g.

How do I tell castle to find an implementation for ILog and then If I drop log4net among the assemblies in the executing directory, it should pick it and use it. Tomorrow if I decide to change log4net to Nlog it should pick up Nlog to log (both obviously should implement ILog)

+3  A: 

You generally should not be so implicit. What if more than one impl is provided? What if you accidentally drop something you didn't intend to?

Having said that, you should use either config file to explicitly tell Windsor in XML which type fulfills your service, or use Binsor if you want more flexibility. There's no magical method in the code "for this service pick whatever implementation there is in any assembly in this folder" and it's very unlikely there will ever be.

And for the specific scenario of loggers, you can use Windsor's Logging facility.

Krzysztof Koźmic
correct me, isn't this a popular concept in the Java world?
Quintin Par
I'm not familiar with how that looks in Java. In .NET if you want to work this way, perhaps MEF is better option for you than IoC container (or a hybrid)
Krzysztof Koźmic
To me, MEF is a good option, yet I don't like being obliged to declare "exports".
fredlegrain
@Krzysztof Koźmic : That could be a nice Facility for Windsor. Why is it "unlikely there will ever be"?
fredlegrain
It's unlikely because it is a very complicated topic, doing so tends to perform very badly and I generally don't see this as very useful.It is however implementable and if you feel the need to do so and have valid reasons for it, than go ahead. I would however think twice if that is really the best way to go.
Krzysztof Koźmic