title: How to trigger Autofac constructor injection in WCF Rest?
body: <p>I am building a WCF REST service and want to use Autofac as DI container. I want to be able to call a parameterized constructor of the service class. Below is my code:</p>
  
  <pre><code>[ServiceContract]
  [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
  [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
  public partial class QDService:IQDService
  {
      public QDService(IApplicationService appService)
      {
          this.appService = appService;
      }
  
      private readonly IApplicationService appService;
  }
  </code></pre>
  
  <p>Then in the global.asax, I set up the config by following <a href="https://stackoverflow.com/questions/6680500/autofac-wcf-rest-4-0">this chapter</a>:</p>
  
  <pre><code>  private void RegisterRoutes()
      {
          var builder = new ContainerBuilder();
          builder.RegisterType&lt;QDService&gt;();
          builder.RegisterType&lt;ApplicationService&gt;().As&lt;IApplicationService&gt;();
          var container = builder.Build();
          AutofacHostFactory.Container = container;
  
          var factory = new AutofacWebServiceHostFactory();
  
          RouteTable.Routes.Add(new ServiceRoute("QDService", factory, typeof(QDService)));
  
      }
  </code></pre>
  
  <p>Below is the method I'm going to call:</p>
  
  <pre><code> [WebInvoke(Method = "GET"
    , ResponseFormat = WebMessageFormat.Xml
    , BodyStyle = WebMessageBodyStyle.Bare
    , UriTemplate = "/Test/{test}")]
      public string Test(string test)
      {
          return "HelloWorld!";
      }
  </code></pre>
  
  <p>After I start up the project and browse to </p>
  
  <pre><code>http://localhost:1685/QDService/Test/1
  </code></pre>
  
  <p>The browser throw me an exception like :</p>
  
  <pre><code>The server encountered an error processing the request. Please see the service help page for constructing valid requests to the service.
  </code></pre>
  
  <p>, I used the firebug to track it and found this:
  <img src="https://i.stack.imgur.com/ok6LQ.png" alt="enter image description here"></p>
  
  <p>I didn't know what caused this but after I removed the parameterized constructor, all worked fine for me . Then I had a quick search on the net but got nothing. Need your help, thx.</p>