Merge pull request #6 from InfinitTechnologies/master
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)
|
||||
where TUser : IdentityUser
|
||||
{
|
||||
// Add the AspNet identity system to work with our RavenDB identity objects.
|
||||
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;
|
||||
return AddRavenDbIdentity<TUser, IdentityRole>(services, setupAction);
|
||||
}
|
||||
|
||||
/// <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)
|
||||
/// <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, 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));
|
||||
return serviceCollection;
|
||||
|
||||
Reference in New Issue
Block a user