Added TRole : IdentityRole generic parameter to AddRavenDbIdentity.
This commit is contained in:
@@ -22,40 +22,55 @@ namespace Raven.Identity
|
|||||||
public static IServiceCollection AddRavenDbIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> setupAction = null)
|
public static IServiceCollection AddRavenDbIdentity<TUser>(this IServiceCollection services, Action<IdentityOptions> setupAction = null)
|
||||||
where TUser : IdentityUser
|
where TUser : IdentityUser
|
||||||
{
|
{
|
||||||
// Add the AspNet identity system to work with our RavenDB identity objects.
|
return AddRavenDbIdentity<TUser>(services, setupAction);
|
||||||
if (setupAction != null)
|
|
||||||
{
|
|
||||||
services.AddIdentity<TUser, IdentityRole>(setupAction)
|
|
||||||
.AddDefaultTokenProviders();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
services.AddIdentity<TUser, IdentityRole>()
|
|
||||||
.AddDefaultTokenProviders();
|
|
||||||
}
|
|
||||||
|
|
||||||
services.AddScoped<Microsoft.AspNetCore.Identity.IUserStore<TUser>, UserStore<TUser>>();
|
|
||||||
services.AddScoped<Microsoft.AspNetCore.Identity.IRoleStore<IdentityRole>, RoleStore<IdentityRole>>();
|
|
||||||
|
|
||||||
return services;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers a RavenDB <see cref="IAsyncDocumentSession"/> to be created and disposed on each request.
|
/// Registers a RavenDB as the user store.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <example>
|
/// <typeparam name="TUser">The type of user. This should be a class you created derived from <see cref="IdentityUser"/>.</typeparam>
|
||||||
/// <code>
|
/// <typeparam name="TRole">The type of role. This should be a class you created derived from <see cref="IdentityRole"/>.</typeparam>
|
||||||
/// public void ConfigureServices(IServiceCollection services)
|
/// <param name="services"></param>
|
||||||
/// {
|
/// <param name="setupAction">Identity options configuration.</param>
|
||||||
/// services.AddRavenDbAsyncSession(() => myRavenDocStore);
|
/// <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)
|
||||||
/// </code>
|
where TUser : IdentityUser
|
||||||
/// </example>
|
where TRole : IdentityRole
|
||||||
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
|
{
|
||||||
/// <param name="dbGetter">The function that gets the database.</param>
|
// Add the AspNet identity system to work with our RavenDB identity objects.
|
||||||
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
|
if (setupAction != null)
|
||||||
/// <returns>The same service collection so that multiple calls can be chained.</returns>
|
{
|
||||||
public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func<IDocumentStore> dbGetter)
|
services.AddIdentity<TUser, TRole>(setupAction)
|
||||||
|
.AddDefaultTokenProviders();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
services.AddIdentity<TUser, TRole>()
|
||||||
|
.AddDefaultTokenProviders();
|
||||||
|
}
|
||||||
|
|
||||||
|
services.AddScoped<Microsoft.AspNetCore.Identity.IUserStore<TUser>, UserStore<TUser>>();
|
||||||
|
services.AddScoped<Microsoft.AspNetCore.Identity.IRoleStore<TRole>, RoleStore<TRole>>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers a RavenDB <see cref="IAsyncDocumentSession"/> to be created and disposed on each request.
|
||||||
|
/// </summary>
|
||||||
|
/// <example>
|
||||||
|
/// <code>
|
||||||
|
/// public void ConfigureServices(IServiceCollection services)
|
||||||
|
/// {
|
||||||
|
/// services.AddRavenDbAsyncSession(() => myRavenDocStore);
|
||||||
|
/// }
|
||||||
|
/// </code>
|
||||||
|
/// </example>
|
||||||
|
/// <param name="serviceCollection"> The <see cref="IServiceCollection" /> to add services to. </param>
|
||||||
|
/// <param name="dbGetter">The function that gets the database.</param>
|
||||||
|
/// <remarks>Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs</remarks>
|
||||||
|
/// <returns>The same service collection so that multiple calls can be chained.</returns>
|
||||||
|
public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func<IDocumentStore> dbGetter)
|
||||||
{
|
{
|
||||||
serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => dbGetter().OpenAsyncSession(), ServiceLifetime.Scoped));
|
serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => dbGetter().OpenAsyncSession(), ServiceLifetime.Scoped));
|
||||||
return serviceCollection;
|
return serviceCollection;
|
||||||
|
|||||||
Reference in New Issue
Block a user