title: ASP.Net MVC 4 Web API controller doesn't work with Unity.WebApi
body: <p>My ASP.Net MVC 4 Web API controller doesn't work with Unity.WebApi. In the same project simple controllers works with Unity.Mvc3 properly. But when I run Web API controller derived from ApiController I'm getting a message:</p>
  
  <blockquote>
    <p>{"$id":"1","Message":"An error has occurred.","ExceptionMessage":"Type
    'ElectricTests.Controllers.Api.DocumentsController' does not have a
    default
    constructor","ExceptionType":"System.ArgumentException","StackTrace":"
    at System.Linq.Expressions.Expression.New(Type type)\r\n   at
    System.Web.Http.Internal.TypeActivator.Create[TBase](Type
    instanceType)\r\n   at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage
    request, Type controllerType, Func`1&amp; activator)\r\n   at
    System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage
    request, HttpControllerDescriptor controllerDescriptor, Type
    controllerType)"}</p>
  </blockquote>
  
  <p>My ApiController:</p>
  
  <pre><code>public class DocumentsController : ApiController
  {
      private readonly IDocumentsRepository _repository;
  
      public DocumentsController(IDocumentsRepository repository) {
          _repository = repository;
      }
  
      public IEnumerable&lt;FormattedDocument&gt; GetFormattedDocuments()
      {
          return _repository.GetAllFormattedDocuments();
      }
      ...
  </code></pre>
  
  <p>Bootstrapper.cs:</p>
  
  <pre><code>public static class Bootstrapper {
      public static void Initialise() {
          IUnityContainer container = BuildUnityContainer();
          DependencyResolver.SetResolver(new UnityDependencyResolver(container));
      }
  
      private static IUnityContainer BuildUnityContainer() {
          var container = new UnityContainer();
  
          // register all your components with the container here
          // it is NOT necessary to register your controllers
          // e.g. container.RegisterType&lt;ITestService, TestService&gt;();            
  
          container.RegisterType&lt;IDocumentsRepository, DocumentsRepository&gt;();
          container.RegisterType&lt;IQuestionsRepository, QuestionsRepository&gt;();
          container.RegisterType&lt;ITestRepository, TestsRepository&gt;();
  
          return container;
      }
  }
  </code></pre>
  
  <p>Where is my mistake?</p>