I have a service running on multiple different servers with very similar configurations. I want to be able to use Castle Windsor WCF Facility to generate a client for arbitrary endpoint addresses.
public class ServiceFactory {
public IService GetService(string hostName){
....
}
}
Now, I will know at compile time what all my services will be, so I can do this:
var container = new WindsorContainer();
// ...
container.AddFacility<WcfFacility>(f => f.CloseTimeout = TimeSpan.Zero);
container.Register(Component.For<IService>().AsWcfClient(new DefaultClientModel()
{
Endpoint = WcfEndpoint.BoundTo(new NetTcpBinding()).At("net.tcp://hostname:port")
}).Named("hostname"));
And then do my ServiceFactory like this:
public class ServiceFactory
{
private readonly IWindsorContainer _container;
public ServiceFactory(IWindsorContainer container)
{
_container = container;
}
public IService GetService(string hostName)
{
return _container.Resolve<IService>(hostName);
}
}
But this is not robust against me forgetting to configure a particular endpoint. Is there a more elegant solution?