diff --git a/RavenDB.Identity/ServiceCollectionExtensions.cs b/RavenDB.Identity/ServiceCollectionExtensions.cs index f76c3b8..8e2bd8a 100644 --- a/RavenDB.Identity/ServiceCollectionExtensions.cs +++ b/RavenDB.Identity/ServiceCollectionExtensions.cs @@ -22,40 +22,55 @@ namespace Raven.Identity public static IServiceCollection AddRavenDbIdentity(this IServiceCollection services, Action setupAction = null) where TUser : IdentityUser { - // Add the AspNet identity system to work with our RavenDB identity objects. - if (setupAction != null) - { - services.AddIdentity(setupAction) - .AddDefaultTokenProviders(); - } - else - { - services.AddIdentity() - .AddDefaultTokenProviders(); - } - - services.AddScoped, UserStore>(); - services.AddScoped, RoleStore>(); - - return services; + return AddRavenDbIdentity(services, setupAction); } - /// - /// Registers a RavenDB to be created and disposed on each request. - /// - /// - /// - /// public void ConfigureServices(IServiceCollection services) - /// { - /// services.AddRavenDbAsyncSession(() => myRavenDocStore); - /// } - /// - /// - /// The to add services to. - /// The function that gets the database. - /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs - /// The same service collection so that multiple calls can be chained. - public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func dbGetter) + /// + /// Registers a RavenDB as the user store. + /// + /// The type of user. This should be a class you created derived from . + /// The type of role. This should be a class you created derived from . + /// + /// Identity options configuration. + /// The same service collection so that multiple calls can be chained. + public static IServiceCollection AddRavenDbIdentity(this IServiceCollection services, Action 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(setupAction) + .AddDefaultTokenProviders(); + } + else + { + services.AddIdentity() + .AddDefaultTokenProviders(); + } + + services.AddScoped, UserStore>(); + services.AddScoped, RoleStore>(); + + return services; + } + + /// + /// Registers a RavenDB to be created and disposed on each request. + /// + /// + /// + /// public void ConfigureServices(IServiceCollection services) + /// { + /// services.AddRavenDbAsyncSession(() => myRavenDocStore); + /// } + /// + /// + /// The to add services to. + /// The function that gets the database. + /// Based on code from https://github.com/maqduni/AspNetCore.Identity.RavenDb/blob/master/src/Maqduni.AspNetCore.Identity.RavenDb/RavenDbServiceCollectionExtensions.cs + /// The same service collection so that multiple calls can be chained. + public static IServiceCollection AddRavenDbAsyncSession(this IServiceCollection serviceCollection, Func dbGetter) { serviceCollection.Add(new ServiceDescriptor(typeof(IAsyncDocumentSession), p => dbGetter().OpenAsyncSession(), ServiceLifetime.Scoped)); return serviceCollection;