views:

77

answers:

2

I am using a IoC Container (Castle Windsor) to instantiate classes accordingly to the configuration file. If I want to add classes from a new dll that didn't exist when I compiled the project, there is any way to do that without recompiling?

Edit: As this project is a Service Host for WCF service, and the classes that I want to include after compilation are WCF Services I would like also to know if I can include endpoint information about new services without recompiling.

+6  A: 

I don't know about Windsor in particular, but I'd expect it to be possible - just specify the full type name including the assembly name:

<component id="foo"
           service="Namespace.IInterfaceName, InterfaceAssembly"
           type="Namespace.ImplementationName, ImplementationAssembly" />
Jon Skeet
And what about WCF? Can I include a service in the endpoint configuration without recompiling?
Jader Dias
@Jader: I don't know enough about WCF to say, I'm afraid. But again, if you're already specifying a type there, including the assembly, then I'd expect it to just work.
Jon Skeet
I just tested and it works (both WCF and Castle Windsor).
Jader Dias
+1  A: 

Yes - that's exactly what Castle Windsor is for. I'm using Castle in a project at home and I use it to dynamically load classes from assemblies that probably didn't exist when I created the class.

The trick is that the classes you load have to implement an interface known to your application.

The point of doing this is so that you can switch in and out different functionality as needed. Your project uses ISaveMyData to save stuff and uses Castle Windsor to use either Oracle or MySql depending on maybe what's installed at the client site.

As for WCF, WCF components already must specify an interface they're using (their contract). In the normal configuration for WCF components you can change the endpoint address and other information to point to different components whenever you need to as long as they use the same contract. No Castle Windsor is needed for that. No recompiling is needed either - just make the configuration change and go.

Terry Donaghe
But if I want the same Application to change the hosted service interface without recompile I'll need the IoC container.
Jader Dias
Wait - you're saying that you want to switch one WCF component with another that uses a different interface entirely?
Terry Donaghe
I built a Service host that can host any service, any interface. That's why I wanted to do exactly what you described.
Jader Dias
Ahh... ok. Cool!
Terry Donaghe