Added TRole : IdentityRole generic parameter to AddRavenDbIdentity.

This commit is contained in:
Josh Close
2019-02-27 23:44:11 -06:00
parent c014fec800
commit 9e3efbd7e4
@@ -21,21 +21,36 @@ namespace Raven.Identity
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddRavenDbIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> setupAction = null)
where TUser : IdentityUser
{
return AddRavenDbIdentity<TUser>(services, setupAction);
}
/// <summary>
/// Registers a RavenDB as the user store.
/// </summary>
/// <typeparam name="TUser">The type of user. This should be a class you created derived from <see cref="IdentityUser"/>.</typeparam>
/// <typeparam name="TRole">The type of role. This should be a class you created derived from <see cref="IdentityRole"/>.</typeparam>
/// <param name="services"></param>
/// <param name="setupAction">Identity options configuration.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddRavenDbIdentity<TUser, TRole>(this IServiceCollection services, Action<IdentityOptions> setupAction = null)
where TUser : IdentityUser
where TRole : IdentityRole
{
// Add the AspNet identity system to work with our RavenDB identity objects.
if (setupAction != null)
{
services.AddIdentity<TUser, IdentityRole>(setupAction)
services.AddIdentity<TUser, TRole>(setupAction)
.AddDefaultTokenProviders();
}
else
{
services.AddIdentity<TUser, IdentityRole>()
services.AddIdentity<TUser, TRole>()
.AddDefaultTokenProviders();
}
services.AddScoped<Microsoft.AspNetCore.Identity.IUserStore<TUser>, UserStore<TUser>>();
services.AddScoped<Microsoft.AspNetCore.Identity.IRoleStore<IdentityRole>, RoleStore<IdentityRole>>();
services.AddScoped<Microsoft.AspNetCore.Identity.IRoleStore<TRole>, RoleStore<TRole>>();
return services;
}