/
AbpZeroServiceCollectionExtensions.cs
87 lines (72 loc) · 4.34 KB
/
AbpZeroServiceCollectionExtensions.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using Abp.Application.Editions;
using Abp.Application.Features;
using Abp.Authorization;
using Abp.Authorization.Roles;
using Abp.Authorization.Users;
using Abp.MultiTenancy;
using Abp.Zero.Configuration;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions;
// ReSharper disable once CheckNamespace - This is done to add extension methods to Microsoft.Extensions.DependencyInjection namespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class AbpZeroServiceCollectionExtensions
{
public static AbpIdentityBuilder AddAbpIdentity<TTenant, TUser, TRole>(this IServiceCollection services)
where TTenant : AbpTenant<TUser>
where TRole : AbpRole<TUser>, new()
where TUser : AbpUser<TUser>
{
return services.AddAbpIdentity<TTenant, TUser, TRole>(setupAction: null);
}
public static AbpIdentityBuilder AddAbpIdentity<TTenant, TUser, TRole>(this IServiceCollection services, Action<IdentityOptions> setupAction)
where TTenant : AbpTenant<TUser>
where TRole : AbpRole<TUser>, new()
where TUser : AbpUser<TUser>
{
services.AddSingleton<IAbpZeroEntityTypes>(new AbpZeroEntityTypes
{
Tenant = typeof(TTenant),
Role = typeof(TRole),
User = typeof(TUser)
});
//AbpTenantManager
services.TryAddScoped<AbpTenantManager<TTenant, TUser>>();
//AbpEditionManager
services.TryAddScoped<AbpEditionManager>();
//AbpRoleManager
services.TryAddScoped<AbpRoleManager<TRole, TUser>>();
services.TryAddScoped(typeof(RoleManager<TRole>), provider => provider.GetService(typeof(AbpRoleManager<TRole, TUser>)));
//AbpUserManager
services.TryAddScoped<AbpUserManager<TRole, TUser>>();
services.TryAddScoped(typeof(UserManager<TUser>), provider => provider.GetService(typeof(AbpUserManager<TRole, TUser>)));
//SignInManager
services.TryAddScoped<AbpSignInManager<TTenant, TRole, TUser>>();
services.TryAddScoped(typeof(SignInManager<TUser>), provider => provider.GetService(typeof(AbpSignInManager<TTenant, TRole, TUser>)));
//AbpLogInManager
services.TryAddScoped<AbpLogInManager<TTenant, TRole, TUser>>();
//AbpUserClaimsPrincipalFactory
services.TryAddScoped<AbpUserClaimsPrincipalFactory<TUser, TRole>>();
services.TryAddScoped(typeof(UserClaimsPrincipalFactory<TUser, TRole>), provider => provider.GetService(typeof(AbpUserClaimsPrincipalFactory<TUser, TRole>)));
services.TryAddScoped(typeof(IUserClaimsPrincipalFactory<TUser>), provider => provider.GetService(typeof(AbpUserClaimsPrincipalFactory<TUser, TRole>)));
//AbpSecurityStampValidator
services.TryAddScoped<AbpSecurityStampValidator<TTenant, TRole, TUser>>();
services.TryAddScoped(typeof(SecurityStampValidator<TUser>), provider => provider.GetService(typeof(AbpSecurityStampValidator<TTenant, TRole, TUser>)));
services.TryAddScoped(typeof(ISecurityStampValidator), provider => provider.GetService(typeof(AbpSecurityStampValidator<TTenant, TRole, TUser>)));
//PermissionChecker
services.TryAddScoped<PermissionChecker<TRole, TUser>>();
services.TryAddScoped(typeof(IPermissionChecker), provider => provider.GetService(typeof(PermissionChecker<TRole, TUser>)));
//AbpUserStore
services.TryAddScoped<AbpUserStore<TRole, TUser>>();
services.TryAddScoped(typeof(IUserStore<TUser>), provider => provider.GetService(typeof(AbpUserStore<TRole, TUser>)));
//AbpRoleStore
services.TryAddScoped<AbpRoleStore<TRole, TUser>>();
services.TryAddScoped(typeof(IRoleStore<TRole>), provider => provider.GetService(typeof(AbpRoleStore<TRole, TUser>)));
//AbpFeatureValueStore
services.TryAddScoped<AbpFeatureValueStore<TTenant, TUser>>();
services.TryAddScoped(typeof(IFeatureValueStore), provider => provider.GetService(typeof(AbpFeatureValueStore<TTenant, TUser>)));
return new AbpIdentityBuilder(services.AddIdentity<TUser, TRole>(setupAction), typeof(TTenant));
}
}
}