title: User.IsInRole() does not work right after role assignment, but does after re-login
body: <p>In a ASP.NET MVC 5 application I'm using Unity container to create OWIN/Identity objects and resolve all the dependencies.</p>
  
  <p>The problem is when I register as a new user and assign him a role like this</p>
  
  <pre><code>userManager.AddToRole(user.Id, "NewUser");
  ...
  await userManager.UpdateAsync(user);
  </code></pre>
  
  <p>it actually creates a record in AspNetUserRoles table, but right after that if I check his role with <code>User.IsInRole("NewUser")</code> I get false, unless I log out and then log in again, then it is true.</p>
  
  <p>I guess the problem could be with Identity objects (UserManager, RoleManager, etc.) lifetime management in Unity context.</p>
  
  <p>UnityConfig.cs</p>
  
  <pre><code>public static void RegisterTypes(IUnityContainer container)
  {
      // DbContext
      container.RegisterType&lt;DbContext, AppEntitiesDbContext&gt;();
      container.RegisterType&lt;AppIdentityDbContext&gt;();
  
      // Identity
      container.RegisterType&lt;IUserStore&lt;ApplicationUser&gt;, UserStore&lt;ApplicationUser&gt;&gt;(
                  new InjectionConstructor(typeof(AppIdentityDbContext)));
  
      container.RegisterType&lt;IAuthenticationManager&gt;(
                  new InjectionFactory(c =&gt; HttpContext.Current.GetOwinContext().Authentication));
  
      container.RegisterType&lt;IRoleStore&lt;IdentityRole, string&gt;, RoleStore&lt;IdentityRole&gt;&gt;(
                  new InjectionConstructor(typeof(AppIdentityDbContext)));
  
       container.RegisterType&lt;ApplicationUserManager&gt;();
       container.RegisterType&lt;ApplicationSignInManager&gt;();
       container.RegisterType&lt;ApplicationRoleManager&gt;();
  }
  </code></pre>
  
  <p>IdentityConfig.cs 
  (I use <code>&lt;add key="owin:AppStartup" value="MyApp.IdentityConfig" /&gt;</code> in Web.config)</p>
  
  <pre><code>public class IdentityConfig
  {
      public void Configuration(IAppBuilder app)
      {
          var container = UnityConfig.GetConfiguredContainer();
  
          app.CreatePerOwinContext(() =&gt; container.Resolve&lt;AppIdentityDbContext&gt;());
          app.CreatePerOwinContext(() =&gt; container.Resolve&lt;ApplicationUserManager&gt;());
          app.CreatePerOwinContext(() =&gt; container.Resolve&lt;ApplicationSignInManager&gt;());
          app.CreatePerOwinContext(() =&gt; container.Resolve&lt;ApplicationRoleManager&gt;());
  
          app.UseCookieAuthentication(new CookieAuthenticationOptions
          {
              AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
                  LoginPath = new PathString("/Account/Login")
          });
      }
  }
  </code></pre>