title: Unity WebAPI: Unable to resolve individual types
body: <p>I have created a standalone WebAPI (no client) and have tried to start implementing DI using the Unity container for WebAPI. </p>
  
  <p>However, when specifying my providers in the OAuthServerOptions (which depend on a custom token authentication service), I am unable to manually specify what they should resolve to.</p>
  
  <p>If someone could point me as to where I am going wrong as it seems to work a bit differently than Unity with MVC.</p>
  
  <p><strong>Unity Config:</strong></p>
  
  <p><code>.RegisterComponents()</code> is called in Startup.cs.</p>
  
  <pre><code>public static class UnityConfig
  {
      public static void RegisterComponents()
      {
          var container = new UnityContainer();
  
          // These two are the ones which won't resolve!
          container.RegisterType&lt;IAuthenticationTokenProvider, SimpleRefreshTokenProvider&gt;();
          container.RegisterType&lt;IOAuthAuthorizationServerProvider, SimpleAuthorizationServerProvider&gt;();
  
          container.RegisterType&lt;ITokenAuthenticationManager, TokenAuthenticationManager&gt;(new HierarchicalLifetimeManager());
  
          // Some more type registrations which work fine...
  
          GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
      }
  }
  </code></pre>
  
  <p><strong>Startup.Auth:</strong></p>
  
  <p>This is where I am unable to manually resolve the providers...</p>
  
  <pre><code>public partial class Startup
  {
      public static OAuthAuthorizationServerOptions OAuthServerOptions { get; private set; }
  
      public void ConfigureAuth(IAppBuilder app)
      {
          // Some OWIN context setups...
  
          // Auth server setup
          OAuthServerOptions = new OAuthAuthorizationServerOptions
          {
              TokenEndpointPath = new PathString("/Token"),
              Provider = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IOAuthAuthorizationServerProvider)),
              RefreshTokenProvider = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IAuthenticationTokenProvider)),
              AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(timeSpan.TotalMinutes + 5),
              AllowInsecureHttp = true
          };
  
          // Enable bearer tokens...
      }
  }
  </code></pre>
  
  <p><strong>Startup:</strong></p>
  
  <pre><code>public partial class Startup
  {  
       public void Configuration(IAppBuilder app)
          {
              HttpConfiguration config = new HttpConfiguration();
  
              UnityConfig.RegisterComponents();     
  
              ConfigureAuth(app);
  
              WebApiConfig.Register(config);
  
              app.UseCors(CorsOptions.AllowAll);
  
              app.UseWebApi(config);
          }
      }
  </code></pre>
  
  <p><strong>SimpleAuthorizationServiceProvider:</strong></p>
  
  <pre><code>// Note: OAuthAuthoizationServiceProvider implements IOAuthAuthorizationServerProvider
  
  public class SimpleAuthorizationServerProvider : OAuthAuthorizationServerProvider
  {
      private ITokenAuthenticationManager tokenAuthenticationManager;
  
      public SimpleAuthorizationServerProvider(ITokenAuthenticationManager tokenAuthenticationManager)
      {
          this.tokenAuthenticationManager = tokenAuthenticationManager;
      }
  }
  </code></pre>
  
  <p><strong>SimpleRefreshTokenProvider:</strong></p>
  
  <pre><code>public class SimpleRefreshTokenProvider : IAuthenticationTokenProvider
  {
      private ITokenAuthenticationManager tokenAuthenticationManager;
  
      public SimpleRefreshTokenProvider(ITokenAuthenticationManager tokenAuthenticationManager)
      {
          this.tokenAuthenticationManager = tokenAuthenticationManager;
      }
  }
  </code></pre>