title: Error while trying to use an IoC container inside WebApi (Net Framework)
body: <p>I'm trying to use an IoC container inside the WebApi template.  I've created an empty Web App Framework project, and selected to use WebApi.  I've then added the Unity NuGet package and added the following to Application_Start:</p>
  
  <pre><code>protected void Application_Start()
  {
      GlobalConfiguration.Configure(WebApiConfig.Register);
      UnityConfig.Register();
  }
  </code></pre>
  
  <p>The UnityConfig:</p>
  
  <pre><code>public class UnityConfig
  {
      public static UnityContainer Register()
      {
          var container = new UnityContainer();
          container.RegisterType&lt;IMyClass, MyClass&gt;();
  
          GlobalConfiguration.Configuration.DependencyResolver = new UnityResolver(container);
  
          return container;
      }
  
  }
  </code></pre>
  
  <p>My UnityResolver is here (the code is largely plagiarised, but it seems pretty bog standard):</p>
  
  <pre><code>public class UnityResolver : IDependencyResolver
  {
      protected IUnityContainer container;
  
      public UnityResolver(IUnityContainer container)
      {
          if (container == null)
          {
              throw new ArgumentNullException("container");
          }
          this.container = container;
      }
  
      public object GetService(Type serviceType)
      {
          try
          {
              return container.Resolve(serviceType);
          }
          catch (ResolutionFailedException)
          {
              return null;
          }
      }
  
      public IEnumerable&lt;object&gt; GetServices(Type serviceType)
      {
          try
          {
              return container.ResolveAll(serviceType);
          }
          catch (ResolutionFailedException)
          {
              return new List&lt;object&gt;();
          }
      }
  
      public IDependencyScope BeginScope()
      {
          var child = container.CreateChildContainer();
          return new UnityResolver(child);
      }
  
      public void Dispose()
      {
          Dispose(true);
      }
  
      protected virtual void Dispose(bool disposing)
      {
          container.Dispose();
      }
  }
  </code></pre>
  
  <p>When I now run this, I get the following error:</p>
  
  <blockquote>
    <p>Unity.Exceptions.ResolutionFailedException: 'Resolution of the
    dependency failed, type =
    'System.Web.Http.Hosting.IHostBufferPolicySelector', name = '(none)'.
    Exception occurred while: while resolving. Exception is:
    InvalidOperationException - The current type,
    System.Web.Http.Hosting.IHostBufferPolicySelector, is an interface and
    cannot be constructed. Are you missing a type mapping?
    ----------------------------------------------- At the time of the exception, the container was:    Resolving
    System.Web.Http.Hosting.IHostBufferPolicySelector,(none) '</p>
  </blockquote>
  
  <p>Clearly, after telling it which IoC library I want to use, I need to inject some internal dependencies, or tell it to, or perhaps, register this earlier (or later).</p>