5

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?

KevinT
  • 3,094
  • 4
  • 26
  • 29
  • Why don't you know what the URI is? Where are you getting your URI from? – Aran Mulholland Oct 10 '12 at 06:05
  • The service that knows the URI is in the container. I don't want to reference the container in a service-locator fashion. Janco's is what I was looking for! – KevinT Oct 15 '12 at 14:02

2 Answers2

4

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.

jancow
  • 401
  • 2
  • 3
0

I think you want to use the UsingFactoryMethod to create your services.

  • I would register a custom UriResolver with the container
  • Resolve an instance of the said UriResolver in the factory method (which doesn't get called until the service needs to be resolved)
  • Create the service in the factory method
  • Search through the Castle Windsor doco and swear a lot.

The following links may be of use

ravendb, castle IoC ,Wcf facility - doc session liefstyle

Using Castle Windsor WcfFacility to create client endpoints

http://www.mail-archive.com/castle-project-users@googlegroups.com/msg09012.html (this one looks to have similar code to what you need)

https://stackoverflow.com/questions/10250077/problems-using-castle-windsor-factory-method

Passing parameters to UsingFactoryMethod in Castle Windsor

Castle Windsor: UsingFactoryMethod can't instantiate with a weird error

http://docs.castleproject.org/Default.aspx?Page=Typed-Factory-Facility-interface-based-factories&NS=Windsor&AspxAutoDetectCookieSupport=1

Community
  • 1
  • 1
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228