-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
UsersServiceCollectionExtensions.cs
54 lines (48 loc) · 2.61 KB
/
UsersServiceCollectionExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OrchardCore.Data;
using OrchardCore.Roles.Services;
using OrchardCore.Security;
using OrchardCore.Security.Services;
using OrchardCore.Users;
using OrchardCore.Users.Handlers;
using OrchardCore.Users.Indexes;
using OrchardCore.Users.Services;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Provides extension methods for <see cref="IServiceCollection"/>.
/// </summary>
public static class UsersServiceCollectionExtensions
{
/// <summary>
/// Registers the users services.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
public static IServiceCollection AddUsers(this IServiceCollection services)
{
services.TryAddScoped<UserStore>();
services.TryAddScoped<IUserStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserRoleStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserPasswordStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserEmailStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserSecurityStampStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserLoginStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserClaimStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.TryAddScoped<IUserAuthenticationTokenStore<IUser>>(sp => sp.GetRequiredService<UserStore>());
services.AddScoped<NullRoleStore>();
services.TryAddScoped<IRoleClaimStore<IRole>>(sp => sp.GetRequiredService<NullRoleStore>());
services.TryAddScoped<IRoleStore<IRole>>(sp => sp.GetRequiredService<NullRoleStore>());
services.TryAddScoped<RoleManager<IRole>>();
services.TryAddScoped<IRoleService, RoleService>();
services.AddIndexProvider<UserIndexProvider>();
services.AddIndexProvider<UserByRoleNameIndexProvider>();
services.AddIndexProvider<UserByLoginInfoIndexProvider>();
services.AddIndexProvider<UserByClaimIndexProvider>();
services.AddScoped<IUserService, UserService>();
services.AddScoped<IUserClaimsPrincipalFactory<IUser>, DefaultUserClaimsPrincipalProviderFactory>();
services.AddScoped<IUserEventHandler, UserDisabledEventHandler>();
return services;
}
}
}