title: .NET Core identity multiple User types
body: <p>I have multiple classes (<code>A</code>, <code>B</code> and <code>C</code>) each extends <code>IdentityUser&lt;Guid&gt;</code>. I also have a class called <code>UserRole</code> which extends <code>IdentityRole&lt;Guid&gt;</code>.</p>
  
  <p>The following is my <code>DbContext</code>:</p>
  
  <pre><code>public sealed class EntityDbContext: DbContext
  {
      public DbSet&lt;A&gt; As { get; set; }
  
      public DbSet&lt;B&gt; Bs { get; set; }
  
      public DbSet&lt;C&gt; Cs { get; set; }
  
  }
  </code></pre>
  
  <p>I added identities to <code>IServiceCollection</code>:</p>
  
  <pre><code>        services
              .AddIdentityCore&lt;A&gt;()
              .AddEntityFrameworkStores&lt;EntityDbContext&gt;()
              .AddRoles&lt;UserRole&gt;()
              .AddUserStore&lt;AUserStore&gt;()
              // .AddRoleStore&lt;TRoleStore&gt;()
              .AddDefaultTokenProviders();
  
          // Same for B, C
  </code></pre>
  
  <p>I also have the following stores:</p>
  
  <pre><code>public class AUserStore : UserStore&lt;A, UserRole, EntityDbContext, Guid&gt; { } 
  public class BUserStore : UserStore&lt;B, UserRole, EntityDbContext, Guid&gt; { } 
  public class CUserStore : UserStore&lt;C, UserRole, EntityDbContext, Guid&gt; { } 
  </code></pre>
  
  <p>The following is the error I'm getting:</p>
  
  <blockquote>
    <p>Specified argument was out of the range of valid values. (Parameter
    'instance 'AUserStore' with ReturnType AUserStore cannot be cast to
    IUserStore')</p>
  </blockquote>
  
  <p>I don't know if what I'm doing is possible or not. Thanks for any help or hint.</p>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>I think I got it working:</p>
  
  <pre><code>class GenericUserRoleStore : RoleStore&lt;UserRole, EntityDbContext, Guid&gt; { }
  
          services.AddIdentity&lt;A, UserRole&gt;()
              .AddDefaultTokenProviders()
              .AddUserStore&lt;AUserStore&gt;()
              .AddRoleStore&lt;GenericUserRoleStore&gt;();
  
          services.AddIdentityCore&lt;B&gt;()
              .AddRoles&lt;UserRole&gt;()
              .AddDefaultTokenProviders()
              .AddUserStore&lt;BUserStore&gt;()
              .AddRoleStore&lt;GenericUserRoleStore&gt;();
  
          services.AddIdentityCore&lt;C&gt;()
              .AddRoles&lt;UserRole&gt;()
              .AddDefaultTokenProviders()
              .AddUserStore&lt;CUserStore&gt;()
              .AddRoleStore&lt;GenericUserRoleStore&gt;();
  </code></pre>