Api Controller has a parameterless public constructor error
<p>I am using Unity to do my DI and I have encountered the following error:-</p>

<p>"An error occurred when trying to create a controller of type 'UploadController'. Make sure that the controller has a parameterless public constructor."</p>

<p>I have the following UnityResolver:-</p>

<pre><code>public class UnityResolver : IDependencyResolver, IDependencyScope, System.Web.Http.Dependencies.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()
    {
        container.Dispose();
    }
}
</code></pre>

<p>}</p>

<p>I have created a UnityConfig as follows:-</p>

<pre><code>public static class UnityConfig
{
    public static void RegisterComponents()
    {
        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;();

        BuildUnityContainer();
        GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
    }

    private static IUnityContainer BuildUnityContainer()
    {
        var container = new UnityContainer();

        // register all your components with the container here
        // you don't need to register controllers
        container.RegisterType&lt;IFileHelpers, FileHelpers&gt;();
        container.RegisterType&lt;IDatabaseHelper, DatabaseHelper&gt;();
        container.RegisterType&lt;IPlayersHelpers, PlayersHelpers&gt;();
        container.RegisterType&lt;IBaseRepository, BaseRepository&gt;();
        container.RegisterType&lt;IAttribsRepository, AttribsRepository&gt;();
        container.RegisterType&lt;IPlayerRepository, PlayerRepository&gt;();
        container.RegisterType&lt;IFileRepository, FileRepository&gt;();
        container.RegisterType&lt;IPlayerAttribsRepository, PlayerAttribsRepository&gt;();

        container.RegisterType&lt;FMContext&gt;();
        container.RegisterType&lt;UserManager&lt;ApplicationUser&gt;&gt;(new HierarchicalLifetimeManager());
        container.RegisterType&lt;IUserStore&lt;ApplicationUser&gt;, UserStore&lt;ApplicationUser&gt;&gt;(new HierarchicalLifetimeManager());

        return container;
    }
}
</code></pre>

<p>}</p>

<p>Im initializing everyting in the WebApiConfig.cs</p>

<pre><code>    public static void Register(HttpConfiguration config)
    {
        // Web API configuration and services
        // Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

        // Web API configuration and services
        var container = new UnityContainer();
        UnityConfig.RegisterComponents();
        config.DependencyResolver = new UnityResolver(container);

        config.EnableCors();

        // Web API routes
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
    }
}
</code></pre>

<p>And this is my UploadController class:-</p>

<pre><code>    public class UploadController : ApiController
{
    private readonly IFileHelpers _fileHelpers;
    private readonly IDatabaseHelper _databaseHelper;
    private readonly IPlayersHelpers _playersHelpers;

    public UploadController(IFileHelpers fileHelpers, IDatabaseHelper databaseHelper, IPlayersHelpers playersHelpers)
    {
        _fileHelpers = fileHelpers;
        _databaseHelper = databaseHelper;
        _playersHelpers = playersHelpers;
    }

    public async Task&lt;HttpResponseMessage&gt; Post()
    {........................}
</code></pre>

<p>Can you please help me in determining what am I doing wrong.  Do I need to declare something else for this to work?</p>

<p>Thanks for your help and time</p>