WCF, RouteTables and Castle Windsor

by Naeem Khedarun 7. February 2011 21:27

 

We are using the routing functionality to give our RESTful WCF service nice endpoints, however I ran into trouble, none of our services were being injected.

The service had two constructors which seemed odd, an empty one and one with dependencies specified…

public Api()
{
}

public Api(IBasket basketService)
{
    _basketService = basketService;
}

The injected services were NULL, so I removed the public constructor and got:

image

This sounds like the default WCF factory at work, checking the SVC files we get:

<%@ ServiceHost 
    Language="C#" 
    Factory="Castle.Facilities.WcfIntegration.DefaultServiceHostFactory, Castle.Facilities.WcfIntegration" 
    Service="MyProject.Api" 
%>   

That’s also configured correctly, but we have overridden the default routing, let’s take a look at that:

RouteTable.Routes.Add(new ServiceRoute("Api", new ServiceHostFactory(), typeof(Api)));

That looks like the default WCF factory to me… Doh! Let’s fix that up…

RouteTable.Routes.Add(new ServiceRoute("Api", new DefaultServiceHostFactory(container.Kernel), typeof(IApi)));

Great, we are now using the windsor factory, and we can remove the default parameter-less constructor from our API service.

Tags: , ,
Categories: WCF | C# | Windsor

Comments

rposbo
rposbo United Kingdom on 2/9/2011 6:25:47 AM

Nice! I was getting annoyed with having to have that default constructor in there.. ;)

pingback
rogue-technology.com on 2/11/2011 11:02:51 PM

Pingback from rogue-technology.com

Distributed Weekly 89  —  Scott Banwart's Blog

pingback
gotium.com on 2/16/2011 2:08:34 PM

Pingback from gotium.com

#Fellows | WCF, RouteTables and Castle Windsor «  random misspellings

Comments are closed