title: Why can't service host from Unity.Wcf resolve service's instance correctly?
body: <p>I have a unity container:</p>
  
  <pre><code>var unityContainer = new UnityContainer();
  </code></pre>
  
  <p>configured as follows:</p>
  
  <pre><code>unityContainer.RegisterType&lt;IExampleDomainService, ExampleDomainService&gt;();
  
  unityContainer.RegisterType&lt;IExampleWebService, ExampleWebService&gt;();
  </code></pre>
  
  <p><code>ExampleWebService</code> type and its constructor look as follows:</p>
  
  <pre><code>[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
  public class ExampleWebService
  {
      public ExampleWebService(IExampleDomainService exampleDomainService)
      {
          this.exampleDomainService = exampleDomainService;
      }
  
  // ...
  </code></pre>
  
  <p>and <code>ExampleDomainService</code> has no constructor defined (the problem is the same when I explicitly define a parameterless constructor for this type).</p>
  
  <p>Next, as explained in Unity.Wcf's <a href="http://unitywcf.codeplex.com/" rel="nofollow">documentation</a>:</p>
  
  <blockquote>
    <p>If you are hosting your WCF service within a Windows Service using a <code>ServiceHost</code>, replace the <code>ServiceHost</code> instance with the custom <code>Unity.Wcf.UnityServiceHost</code>. You will find that the <code>UnityServiceHost</code> takes in a Unity container as its first parameter but is otherwise identical to the default <code>ServiceHost</code>.</p>
  </blockquote>
  
  <p>I do the following:</p>
  
  <pre><code> var host = new UnityServiceHost(unityContainer, typeof(ExampleWebService), baseAddress);
  </code></pre>
  
  <p>This however throws <code>System.InvalidOperationException</code> with the following message: </p>
  
  <blockquote>
    <p>The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor. To fix the problem, add a default constructor to the type, or pass an instance of the type to the host.</p>
  </blockquote>
  
  <p>Looking at <a href="https://github.com/gruan01/Unity.WCF.4/blob/master/UnityServiceHost.cs" rel="nofollow"><code>UnityServiceHost</code> implementation at GitHub</a> it passes given <code>serviceType</code> (<code>typeof(ExampleWebService)</code> in this case) directly to WCF's native <code>ServiceHost</code>:</p>
  
  <pre><code>public sealed class UnityServiceHost : ServiceHost
  {
      public UnityServiceHost(IUnityContainer container, Type serviceType, params Uri[] baseAddresses)
        : base(serviceType, baseAddresses)
               ^^^^^^^^^^^
               ???????????
  </code></pre>
  
  <p>which obviously crashes, as <code>ServiceHost</code> does not know anything about Unity and its container and cannot cope when parameterless constructor is missing.</p>
  
  <p>Is Unity.Wcf completely broken for non-WAS/non-IIS hosting or (I hope) I am  doing something completely wrong?</p>