2

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)

Quintin Par
  • 15,862
  • 27
  • 93
  • 146

1 Answers1

3

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 Kozmic
  • 27,267
  • 12
  • 73
  • 115
  • 1
    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 Kozmic Feb 11 '10 at 07:53
  • To me, MEF is a good option, yet I don't like being obliged to declare "exports". – fredlegrain Feb 11 '10 at 10:25
  • 1
    That could be a nice Facility for Windsor. Why is it "unlikely there will ever be"? – fredlegrain Feb 11 '10 at 10:39
  • 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 Kozmic Feb 11 '10 at 11:24