|
| 1 | +using Microsoft.AspNetCore.Identity; |
| 2 | +using Microsoft.Extensions.DependencyInjection.Extensions; |
1 | 3 | using ServiceStack.Auth;
|
2 | 4 | using ServiceStack;
|
3 | 5 | using ServiceStack.Html;
|
@@ -59,5 +61,82 @@ public void Configure(IWebHostBuilder builder) => builder
|
59 | 61 | });
|
60 | 62 |
|
61 | 63 | })));
|
| 64 | + |
| 65 | + services.TryAddScoped(typeof(RoleManager<IdentityRole>), CreateRoleManagerAdapter<ApplicationRole>); |
62 | 66 | });
|
| 67 | + |
| 68 | + public static RoleManager<IdentityRole> CreateRoleManagerAdapter<TRole>(IServiceProvider services) where TRole : class |
| 69 | + { |
| 70 | + //var nativeRoleManager = services.GetRequiredService<RoleManager<TRole>>(); |
| 71 | + var adapter = new RoleManager<IdentityRole>( |
| 72 | + CreateRoleStoreAdapter<TRole>(services), |
| 73 | + [], |
| 74 | + services.GetRequiredService<ILookupNormalizer>(), |
| 75 | + services.GetRequiredService<IdentityErrorDescriber>(), |
| 76 | + new Logger<RoleManager<IdentityRole>>(services.GetRequiredService<ILoggerFactory>()) |
| 77 | + ); |
| 78 | + return adapter; |
| 79 | + } |
| 80 | + |
| 81 | + public static IRoleStore<IdentityRole> CreateRoleStoreAdapter<TRole>(IServiceProvider services) where TRole : class |
| 82 | + { |
| 83 | + return new AdapterRoleStore<TRole>(services.GetRequiredService<IRoleStore<TRole>>()); |
| 84 | + } |
| 85 | + |
| 86 | + class AdapterRoleStore<TRole>(IRoleStore<TRole> store) : IRoleStore<IdentityRole> where TRole : class |
| 87 | + { |
| 88 | + public void Dispose() |
| 89 | + { |
| 90 | + } |
| 91 | + |
| 92 | + public Task<IdentityResult> CreateAsync(IdentityRole role, CancellationToken cancellationToken) |
| 93 | + { |
| 94 | + throw new NotImplementedException(); |
| 95 | + } |
| 96 | + |
| 97 | + public Task<IdentityResult> UpdateAsync(IdentityRole role, CancellationToken cancellationToken) |
| 98 | + { |
| 99 | + throw new NotImplementedException(); |
| 100 | + } |
| 101 | + |
| 102 | + public Task<IdentityResult> DeleteAsync(IdentityRole role, CancellationToken cancellationToken) |
| 103 | + { |
| 104 | + throw new NotImplementedException(); |
| 105 | + } |
| 106 | + |
| 107 | + public Task<string> GetRoleIdAsync(IdentityRole role, CancellationToken cancellationToken) |
| 108 | + { |
| 109 | + throw new NotImplementedException(); |
| 110 | + } |
| 111 | + |
| 112 | + public Task<string?> GetRoleNameAsync(IdentityRole role, CancellationToken cancellationToken) |
| 113 | + { |
| 114 | + throw new NotImplementedException(); |
| 115 | + } |
| 116 | + |
| 117 | + public Task SetRoleNameAsync(IdentityRole role, string? roleName, CancellationToken cancellationToken) |
| 118 | + { |
| 119 | + throw new NotImplementedException(); |
| 120 | + } |
| 121 | + |
| 122 | + public Task<string?> GetNormalizedRoleNameAsync(IdentityRole role, CancellationToken cancellationToken) |
| 123 | + { |
| 124 | + throw new NotImplementedException(); |
| 125 | + } |
| 126 | + |
| 127 | + public Task SetNormalizedRoleNameAsync(IdentityRole role, string? normalizedName, CancellationToken cancellationToken) |
| 128 | + { |
| 129 | + throw new NotImplementedException(); |
| 130 | + } |
| 131 | + |
| 132 | + public Task<IdentityRole?> FindByIdAsync(string roleId, CancellationToken cancellationToken) |
| 133 | + { |
| 134 | + throw new NotImplementedException(); |
| 135 | + } |
| 136 | + |
| 137 | + public Task<IdentityRole?> FindByNameAsync(string normalizedRoleName, CancellationToken cancellationToken) |
| 138 | + { |
| 139 | + throw new NotImplementedException(); |
| 140 | + } |
| 141 | + } |
63 | 142 | }
|
0 commit comments