title: Structure Map and Aspnet.Identity UserManager static class issue
body: <p>I've got an issue with getting correct instance of UserManager in my Account Controller. Currently, I cannot get password reset to work as my provider and other settings are being ignored.</p>
  
  <p>In Startup - void ConfigureAuth(IAppBuilder app) I've got following:</p>
  
  <pre><code>app.CreatePerOwinContext&lt;ViewingBookerDatabaseContext&gt;(ViewingBookerDatabaseContext.Create);
  app.CreatePerOwinContext&lt;ApplicationUserManager&gt;(ApplicationUserManager.Create);
  </code></pre>
  
  <p>Then in AccountManager class, method Create referenced above contains following:</p>
  
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      // Configure the application user manager
      public ApplicationUserManager(ApplicationUserStore store)
          : base(store)
      {
      }
  
  public static ApplicationUserManager Create(IdentityFactoryOptions&lt;ApplicationUserManager&gt; options, IOwinContext context)
      {
          var manager = new ApplicationUserManager(new ApplicationUserStore(new ViewingBookerDatabaseContext()));
  
          // Configure validation logic for usernames
          manager.UserValidator = new UserValidator&lt;ApplicationUser&gt;(manager)
          {
              AllowOnlyAlphanumericUserNames = false,
              RequireUniqueEmail = true
          };
          // Configure validation logic for passwords
          manager.PasswordValidator = new PasswordValidator
          {
              RequiredLength = 6,
              RequireNonLetterOrDigit = false,
              RequireDigit = false,
              RequireLowercase = false,
              RequireUppercase = false,
          };
          // Configure user lockout defaults
          manager.UserLockoutEnabledByDefault = true;
          manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
          manager.MaxFailedAccessAttemptsBeforeLockout = 5;
  
          var dataProtectionProvider = options.DataProtectionProvider;
          if (dataProtectionProvider != null)
          {
              manager.UserTokenProvider = new DataProtectorTokenProvider&lt;ApplicationUser&gt;(dataProtectionProvider.Create("ASP.NET Identity"));
          }
          return manager;
      }
  </code></pre>
  
  <p>Now, this worked great before I installed IoC - in this case StrcutureMap. IoC for controllers is registered in following pattern:</p>
  
  <pre><code>Scan(scan =&gt;
          {
              scan.TheCallingAssembly();
              scan.With(new ControllerConvention());
          });
  
  public class ControllerConvention : IRegistrationConvention
  {
      public void Process(Type type, Registry registry)
      {
          if (type.CanBeCastTo(typeof(Controller)) &amp;&amp; !type.IsAbstract)
          {
              registry.For(type).LifecycleIs(new UniquePerRequestLifecycle());
          }
      }
  }
  </code></pre>
  
  <p>UserManager is then referenced in my AccountController as follows:</p>
  
  <pre><code>private ApplicationUserManager _userManager;
      public ApplicationUserManager UserManager
      {
          get
          {
              return _userManager ?? HttpContext.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
          }
          private set
          {
              _userManager = value;
          }
      }
  
      private IAuthenticationManager _authenticationManager
      {
          get
          {
              return HttpContext.GetOwinContext().Authentication;
          }
      }
  
      public AccountController() 
      {
      }
  
      public AccountController(ApplicationUserManager userManager, ViewingBookerDatabaseContext context, CurrentUser currentUser, Logger logger, EmailService emailService)
      {
          UserManager = userManager;
          _context = context;
          _currentUser = currentUser;
          _logger = logger;
          _emailService = emailService;
      }
  </code></pre>
  
  <p>Now, UserManager is being used for my password reset, account creation etc. After installing IoC, I get "No ITokenProvider is registered" for password reset, account names with @ are being returned as invalid when creating user etc. Looks like AccountController's instance of ApplicationUserManager is not created via Create() method of ApplicationUserManager class.</p>
  
  <p>Can anyone point me to a correct implementation of strucutre map, so it calls Create to get an instance of AccountUserManager rather than returning a generic instance of that class that contains no ITokenProvider spec. etc?</p>
  
  <p>Thanks for your help. </p>