title: Identity 2.2.1 & UserManager with Ninject
body: <p>I've been using Identity 2.2.1 with Ninject on a Web API project and all seems to be working well other than the UserManager. The UserManager is created but when it's injected into a service it only contains it's default implementation and not the configuration it should be using.</p>
  
  <p>I've tried to follow multiple solutions to answers on here but to no avail. Could someone point out where I'm going wrong please.</p>
  
  <p><strong>Startup.cs</strong></p>
  
  <pre><code>public class Startup
  {
      internal static IDataProtectionProvider DataProtectionProvider { get; private set; }
  
      public void Configuration(IAppBuilder app)
      {
          var config = new HttpConfiguration();
          var kernel = NinjectConfig.CreateKernel();
  
          app.UseNinjectMiddleware(() =&gt; kernel);
          WebApiConfig.Register(config);
          ConfigureOAuth(app, kernel);
          app.UseNinjectWebApi(config);
          app.UseWebApi(config);
      }
  
      private void ConfigureOAuth(IAppBuilder app, IKernel kernel)
      {
          DataProtectionProvider = app.GetDataProtectionProvider();
  
          app.CreatePerOwinContext&lt;UserManager&gt;((option, context) =&gt;
          {
              return kernel.Get&lt;UserManager&gt;();
          });
  
          app.UseCors(CorsOptions.AllowAll);
  
          app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
          {
              TokenEndpointPath = new PathString("/token"),
              Provider = new AuthorizationServerProvider(),
              AccessTokenExpireTimeSpan = TimeSpan.FromHours(6),
              AllowInsecureHttp = true    // TODO: Change when in production
          });
  
          app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
      }
  }
  </code></pre>
  
  <p><strong>NinjectConfig.cs</strong></p>
  
  <pre><code>public static class NinjectConfig
  {
      public static IKernel CreateKernel()
      {
          var kernel = new StandardKernel();
          kernel.Load(Assembly.GetExecutingAssembly());
  
          RegisterServices(kernel);
  
          return kernel;
      }
  
      private static void RegisterServices(IKernel kernel)
      {
          GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel);
      }
  }
  </code></pre>
  
  <p><strong>IdentityModule.cs</strong></p>
  
  <pre><code>public class IdentityModule : NinjectModule
  {
      public override void Load()
      {
          Bind&lt;IUserStore&lt;User&gt;&gt;().To&lt;UserStore&lt;User&gt;&gt;().WithConstructorArgument("context", new NeedsCollectorDbContext());
          Bind&lt;UserManager&gt;().ToSelf();
      }
  }
  </code></pre>
  
  <p><strong>UserManager.cs</strong></p>
  
  <pre><code>public class UserManager : UserManager&lt;User&gt;
  {
      public UserManager(IUserStore&lt;User&gt; store) : base(store)
      {
          UserValidator = new UserValidator&lt;User&gt;(this)
          {
              AllowOnlyAlphanumericUserNames = false,
              RequireUniqueEmail = true
          };
  
          PasswordValidator = new PasswordValidator
          {
              RequiredLength = 6,
              RequireNonLetterOrDigit = false,
              RequireDigit = true,
              RequireLowercase = true,
              RequireUppercase = true,
          };
  
          var dataProtectionProvider = Startup.DataProtectionProvider;
          if (dataProtectionProvider != null)
          {
              UserTokenProvider = new DataProtectorTokenProvider&lt;User&gt;(dataProtectionProvider.Create("ASP.NET Identity"));
          }
      }
  }
  </code></pre>
  
  <p>The UserManager gets instantiated with the correct configuration within Startup.cs but when injected into the service later it's lost, please see the screenshots - the UserTokenProvider is null when injected.</p>
  
  <p><a href="https://i.stack.imgur.com/VXeJg.png" rel="nofollow noreferrer">Startup.cs</a></p>
  
  <p><a href="https://i.stack.imgur.com/7hWdW.png" rel="nofollow noreferrer">Within a service</a></p>
  
  <p>Thanks</p>