|
13 | 13 | namespace Microsoft.Extensions.DependencyInjection
|
14 | 14 | {
|
15 | 15 | /// <summary>
|
16 |
| - /// Contains extension methods to <see cref="IdentityBuilder" /> for adding entity framework stores. |
| 16 | + /// Contains extension methods to <see cref="IdentityBuilder" /> for adding linq2db stores. |
17 | 17 | /// </summary>
|
18 | 18 | public static class IdentityLinqToDbBuilderExtensions
|
19 | 19 | {
|
20 | 20 | /// <summary>
|
21 |
| - /// Adds an Entity Framework implementation of identity information stores. |
| 21 | + /// Adds an linq2db plementation of identity information stores. |
22 | 22 | /// </summary>
|
23 |
| - /// <typeparam name="TContext"> |
24 |
| - /// The type of the class for <see cref="IDataContext" />, |
25 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
26 |
| - /// </typeparam> |
27 |
| - /// <typeparam name="TConnection"> |
28 |
| - /// The type of the class for <see cref="DataConnection" />, |
29 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
30 |
| - /// </typeparam> |
31 | 23 | /// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
|
32 | 24 | /// <param name="factory">
|
33 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
| 25 | + /// <see cref="IConnectionFactory" /> |
34 | 26 | /// </param>
|
35 | 27 | /// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
|
36 | 28 | // ReSharper disable once InconsistentNaming
|
37 |
| - public static IdentityBuilder AddLinqToDBStores<TContext, TConnection>(this IdentityBuilder builder, |
38 |
| - IConnectionFactory<TContext, TConnection> factory) |
39 |
| - where TContext : IDataContext |
40 |
| - where TConnection : DataConnection |
| 29 | + public static IdentityBuilder AddLinqToDBStores(this IdentityBuilder builder, IConnectionFactory factory) |
41 | 30 | {
|
42 |
| - builder.Services.AddSingleton(factory); |
| 31 | + return AddLinqToDBStores(builder, factory, |
| 32 | + typeof(string), |
| 33 | + typeof(IdentityUserClaim<string>), |
| 34 | + typeof(IdentityUserRole<string>), |
| 35 | + typeof(IdentityUserLogin<string>), |
| 36 | + typeof(IdentityUserToken<string>), |
| 37 | + typeof(IdentityRoleClaim<string>)); |
| 38 | + } |
43 | 39 |
|
44 |
| - builder.Services.TryAdd( |
45 |
| - GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TConnection))); |
46 |
| - return builder; |
| 40 | + /// <summary> |
| 41 | + /// Adds an linq2db implementation of identity information stores. |
| 42 | + /// </summary> |
| 43 | + /// <typeparam name="TKey">The type of the primary key used for the users and roles.</typeparam> |
| 44 | + /// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param> |
| 45 | + /// <param name="factory"> |
| 46 | + /// <see cref="IConnectionFactory" /> |
| 47 | + /// </param> |
| 48 | + /// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns> |
| 49 | + // ReSharper disable once InconsistentNaming |
| 50 | + public static IdentityBuilder AddLinqToDBStores<TKey>(this IdentityBuilder builder, IConnectionFactory factory) |
| 51 | + where TKey : IEquatable<TKey> |
| 52 | + { |
| 53 | + return AddLinqToDBStores(builder, factory, |
| 54 | + typeof(TKey), |
| 55 | + typeof(IdentityUserClaim<TKey>), |
| 56 | + typeof(IdentityUserRole<TKey>), |
| 57 | + typeof(IdentityUserLogin<TKey>), |
| 58 | + typeof(IdentityUserToken<TKey>), |
| 59 | + typeof(IdentityRoleClaim<TKey>)); |
47 | 60 | }
|
48 | 61 |
|
49 | 62 | /// <summary>
|
50 |
| - /// Adds an Entity Framework implementation of identity information stores. |
| 63 | + /// Adds an linq2db implementation of identity information stores. |
51 | 64 | /// </summary>
|
52 |
| - /// <typeparam name="TContext"> |
53 |
| - /// The type of the class for <see cref="IDataContext" />, |
54 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
55 |
| - /// </typeparam> |
56 |
| - /// <typeparam name="TConnection"> |
57 |
| - /// The type of the class for <see cref="DataConnection" />, |
58 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
59 |
| - /// </typeparam> |
60 | 65 | /// <typeparam name="TKey">The type of the primary key used for the users and roles.</typeparam>
|
| 66 | + /// <typeparam name="TUserClaim">The type representing a claim.</typeparam> |
| 67 | + /// <typeparam name="TUserRole">The type representing a user role.</typeparam> |
| 68 | + /// <typeparam name="TUserLogin">The type representing a user external login.</typeparam> |
| 69 | + /// <typeparam name="TUserToken">The type representing a user token.</typeparam> |
| 70 | + /// <typeparam name="TRoleClaim">The type of the class representing a role claim.</typeparam> |
61 | 71 | /// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
|
62 | 72 | /// <param name="factory">
|
63 |
| - /// <see cref="IConnectionFactory{TContext,TConnection}" /> |
| 73 | + /// <see cref="IConnectionFactory" /> |
64 | 74 | /// </param>
|
65 | 75 | /// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
|
66 | 76 | // ReSharper disable once InconsistentNaming
|
67 |
| - public static IdentityBuilder AddLinqToDBStores<TContext, TConnection, TKey>(this IdentityBuilder builder, |
68 |
| - IConnectionFactory<TContext, TConnection> factory) |
69 |
| - where TContext : IDataContext |
70 |
| - where TConnection : DataConnection |
| 77 | + public static IdentityBuilder AddLinqToDBStores< |
| 78 | + TKey, |
| 79 | + TUserClaim, |
| 80 | + TUserRole, |
| 81 | + TUserLogin, |
| 82 | + TUserToken, |
| 83 | + TRoleClaim>(this IdentityBuilder builder, IConnectionFactory factory) |
| 84 | + where TUserClaim : class, IIdentityUserClaim<TKey> |
| 85 | + where TUserRole : class, IIdentityUserRole<TKey> |
| 86 | + where TUserLogin : class, IIdentityUserLogin<TKey> |
| 87 | + where TUserToken : class, IIdentityUserToken<TKey> |
71 | 88 | where TKey : IEquatable<TKey>
|
| 89 | + where TRoleClaim : class, IIdentityRoleClaim<TKey> |
| 90 | + { |
| 91 | + |
| 92 | + return AddLinqToDBStores(builder, factory, |
| 93 | + typeof(TKey), |
| 94 | + typeof(TUserClaim), |
| 95 | + typeof(TUserRole), |
| 96 | + typeof(TUserLogin), |
| 97 | + typeof(TUserToken), |
| 98 | + typeof(TRoleClaim)); |
| 99 | + } |
| 100 | + |
| 101 | + /// <summary> |
| 102 | + /// Adds an linq2db implementation of identity information stores. |
| 103 | + /// </summary> |
| 104 | + /// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param> |
| 105 | + /// <param name="factory"> |
| 106 | + /// <see cref="IConnectionFactory" /> |
| 107 | + /// </param> |
| 108 | + /// <param name="keyType">The type of the primary key used for the users and roles.</param> |
| 109 | + /// <param name="userClaimType">The type representing a claim.</param> |
| 110 | + /// <param name="userRoleType">The type representing a user role.</param> |
| 111 | + /// <param name="userLoginType">The type representing a user external login.</param> |
| 112 | + /// <param name="userTokenType">The type representing a user token.</param> |
| 113 | + /// <param name="roleClaimType">The type of the class representing a role claim.</param> |
| 114 | + /// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns> |
| 115 | + // ReSharper disable once InconsistentNaming |
| 116 | + public static IdentityBuilder AddLinqToDBStores(this IdentityBuilder builder, IConnectionFactory factory, |
| 117 | + Type keyType, Type userClaimType, Type userRoleType, Type userLoginType, Type userTokenType, Type roleClaimType) |
72 | 118 | {
|
73 | 119 | builder.Services.AddSingleton(factory);
|
74 | 120 |
|
75 |
| - builder.Services.TryAdd(GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TConnection), typeof(TKey))); |
| 121 | + builder.Services.TryAdd(GetDefaultServices( |
| 122 | + keyType, |
| 123 | + builder.UserType, |
| 124 | + userClaimType, |
| 125 | + userRoleType, |
| 126 | + userLoginType, |
| 127 | + userTokenType, |
| 128 | + builder.RoleType, |
| 129 | + roleClaimType)); |
| 130 | + |
76 | 131 | return builder;
|
77 | 132 | }
|
78 | 133 |
|
79 |
| - private static IServiceCollection GetDefaultServices(Type userType, Type roleType, Type contextType, |
80 |
| - Type connectionType, Type keyType = null) |
| 134 | + private static IServiceCollection GetDefaultServices(Type keyType, Type userType, Type userClaimType, Type userRoleType, Type userLoginType, Type userTokenType, Type roleType, Type roleClaimType) |
81 | 135 | {
|
82 |
| - Type userStoreType; |
83 |
| - Type roleStoreType; |
84 |
| - keyType = keyType ?? typeof(string); |
85 |
| - userStoreType = typeof(UserStore<,,,,>).MakeGenericType(contextType, connectionType, userType, roleType, keyType); |
86 |
| - roleStoreType = typeof(RoleStore<,,,>).MakeGenericType(contextType, connectionType, roleType, keyType); |
| 136 | + //UserStore<TKey, TUser, TRole, TUserClaim, TUserRole, TUserLogin, TUserToken> |
| 137 | + var userStoreType = typeof(UserStore<,,,,,,>).MakeGenericType(keyType, userType, roleType, userClaimType, userRoleType, userLoginType, userTokenType); |
| 138 | + // RoleStore<TKey, TRole, TRoleClaim> |
| 139 | + var roleStoreType = typeof(RoleStore<,,>).MakeGenericType(keyType, roleType, roleClaimType); |
87 | 140 |
|
88 | 141 | var services = new ServiceCollection();
|
89 | 142 | services.AddScoped(
|
|
0 commit comments