title: Make sure that the controller has a parameterless public constructor, Microsoft Unity can not resolve parameters
body: <p>I recently create a sample application with Web API template. I also Installed the Microsoft Unity Mvc package and add a test service as following:</p>
  
  <pre><code>public interface IUtilityService
  {
      string GetToken(int length);
  }
  
  public class UtilityService : IUtilityService
  {
      public string GetToken(int length)
      {
          return "ABC";
      }
  }
  </code></pre>
  
  <p>The <code>UnityConfig</code> and <code>UnityWebActivator</code> are just created by installing the package and I just registered my own service in it as following:</p>
  
  <pre><code>public static class UnityWebActivator
  {
      /// &lt;summary&gt;Integrates Unity when the application starts.&lt;/summary&gt;
      public static void Start() 
      {
          var container = UnityConfig.GetConfiguredContainer();
  
          FilterProviders.Providers.Remove(
              FilterProviders.Providers.OfType&lt;FilterAttributeFilterProvider&gt;().First());
          FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
  
          DependencyResolver.SetResolver(new UnityDependencyResolver(container));
  
          // TODO: Uncomment if you want to use PerRequestLifetimeManager
          // Microsoft.Web.Infrastructure.DynamicModuleHelper
          //  .DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
      }
  
      /// &lt;summary&gt;Disposes the Unity container when the application is shut down.&lt;/summary&gt;
      public static void Shutdown()
      {
          var container = UnityConfig.GetConfiguredContainer();
          container.Dispose();
      }
  </code></pre>
  
  <p>And the UnityConfig:</p>
  
  <pre><code>public class UnityConfig
  {
      #region Unity Container
      private static Lazy&lt;IUnityContainer&gt; container = new Lazy&lt;IUnityContainer&gt;(() =&gt;
      {
          var container = new UnityContainer();
          RegisterTypes(container);
          return container;
      });
  
      public static IUnityContainer GetConfiguredContainer()
      {
          return container.Value;
      }
      #endregion
  
      public static void RegisterTypes(IUnityContainer container)
      {
          // NOTE: To load from web.config uncomment the line below. Make sure to 
          // add a Microsoft.Practices.Unity.Configuration to the using statements.
          // container.LoadConfiguration();
  
          // TODO: Register your types here
          container.RegisterType&lt;IUtilityService, UtilityService&gt;();
      }
  }
  </code></pre>
  
  <p>Microsoft Unity resolve my service in the Home controller once I run the test application, However, It can not resolve the service once I want to call a method inside Values controller from the JQuery.</p>
  
  <p>The code are as follow:</p>
  
  <pre><code>private readonly IUtilityService utilityService;
  
  public HomeController(IUtilityService utilityService)
  {
      this.utilityService = utilityService;
  }
  
  public ActionResult Index()
  {
      ViewBag.Title = utilityService.GetToken(10);
  
      return View();
  }
  </code></pre>
  
  <p>And the Values Controller is as follow:</p>
  
  <pre><code>private readonly IUtilityService utilityService;
  
  public ValuesController(IUtilityService utilityService)
  {
      this.utilityService = utilityService;
  }
  
  // GET api/values
  public IEnumerable&lt;string&gt; Get()
  {
      return new string[] { "value1", "value2" };
  }
  </code></pre>
  
  <p>This is also the jquery code I call the Values controller:</p>
  
  <pre><code> $(document).ready(function () {
      console.log("ready!");
  
      $('#call').click(function () {
          $.ajax({
              type: "GET",
              dataType: 'json',
              url: "api/Values",
              success: function (response) {
                  console.log("success!");
              },
              error: function (response, textStatus, errorThrown) {
                  console.log("error!");
              }
          });
      })
  });
  </code></pre>
  
  <p>One I click the button to run the ajax call to the values controller I get the error below and seems the controller can not be initiated because of not having parameter less constructor.</p>
  
  <p>Error:</p>
  
  <blockquote>
    <p>An error occurred when trying to create a controller of type
    'ValuesController'. Make sure that the controller has a parameterless
    public constructor.</p>
  </blockquote>