Search code examples
castle-windsorwcf-client

Registering a WcfClient in the container when the URI not yet known


At the time I am registering a new WCF endpoint I do not know what the URI is...

public void Install(IWindsorContainer container, IConfigurationStore store)
{
   var defaultClientModel = new DefaultClientModel
   {
     Endpoint = WcfEndpoint
       .ForContract<IMyService>()
       .BoundTo(new WSHttpBinding(SecurityMode.None))
       .At(  URI??? )
   };

   container.Register(WcfClient.ForChannels(defaultClientModel));
}

Is there some way I can retrieve the URI from the container at the time the IMyService instance is requested (this is when it is known)?

Is there a factory method/dynamic parameter sort of thing that could be used?


Solution

  • It looks like you're able to do so using the following syntax in Windsor 3.1:

    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
    container.Register(
        Component.For<IMyService>()
        .AsWcfClient()
        .DependsOn((k, d) =>
            d["EndPoint"] = WcfEndpoint.BoundTo(new WSHttpBinding(SecurityMode.None)).At( URI??? )));
    }
    

    Windsor will attempt to resolve the endpoint using the given dynamic resolution delegate at the point when an IMyService is first resolved.