Skip to content

Commit 5c44f84

Browse files
authored
Merge pull request #7 from linq2db/issues
Issues
2 parents 4f3ef98 + ce3bd45 commit 5c44f84

22 files changed

+677
-371
lines changed

samples/IdentitySample.Mvc/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void ConfigureServices(IServiceCollection services)
5353
options.Cookies.ApplicationCookie.DataProtectionProvider =
5454
DataProtectionProvider.Create(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
5555
})
56-
.AddLinqToDBStores(new DefaultConnectionFactory<DataContext, ApplicationDataConnection>())
56+
.AddLinqToDBStores(new DefaultConnectionFactory())
5757
.AddDefaultTokenProviders();
5858

5959
services.AddMvc();

samples/IdentitySample.Mvc/Views/Home/Index.cshtml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
<dl>
1717
<dt>Initialize ASP.NET Identity</dt>
1818
<dd>
19-
You can initialize ASP.NET Identity when the application starts. Since ASP.NET Identity is Entity Framework based in this sample,
20-
you can create DatabaseInitializer which is configured to get called each time the app starts.
19+
You can initialize ASP.NET Identity when the application starts.
2120
<strong>Please look in App_Start\IdentityConfig.cs</strong>
2221
This code shows the following
2322
<ul>

src/LinqToDB.Identity/DefaultConnectionFactory.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@
33
namespace LinqToDB.Identity
44
{
55
/// <summary>
6-
/// Represents default <see cref="IConnectionFactory{TContext,TConnection}" />
6+
/// Represents default <see cref="IConnectionFactory" />
77
/// </summary>
8-
/// <typeparam name="TContext">The type of the data getContext class used to access the store.</typeparam>
9-
/// <typeparam name="TConnection">The type repewsenting database getConnection <see cref="DataConnection" /></typeparam>
10-
public class DefaultConnectionFactory<TContext, TConnection> : IConnectionFactory<TContext, TConnection>
11-
where TContext : class, IDataContext, new()
12-
where TConnection : DataConnection, new()
8+
public class DefaultConnectionFactory : IConnectionFactory
139
{
1410
/// <summary>
1511
/// Creates <see cref="DataConnection" /> with default parameters
1612
/// </summary>
1713
/// <returns>
1814
/// <see cref="DataConnection" />
1915
/// </returns>
20-
public TConnection GetConnection()
16+
public DataConnection GetConnection()
2117
{
22-
return new TConnection();
18+
return new DataConnection();
2319
}
2420

2521
/// <summary>
@@ -28,9 +24,9 @@ public TConnection GetConnection()
2824
/// <returns>
2925
/// <see cref="DataContext" />
3026
/// </returns>
31-
public TContext GetContext()
27+
public IDataContext GetContext()
3228
{
33-
return new TContext();
29+
return new DataContext();
3430
}
3531
}
3632
}

src/LinqToDB.Identity/IConnectionFactory.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,22 @@ namespace LinqToDB.Identity
55
/// <summary>
66
/// Represents connection factory
77
/// </summary>
8-
/// <typeparam name="TContext">
9-
/// <see cref="IDataContext" />
10-
/// </typeparam>
11-
/// <typeparam name="TConnection">
12-
/// <see cref="DataConnection" />
13-
/// </typeparam>
14-
public interface IConnectionFactory<out TContext, out TConnection>
15-
where TContext : IDataContext
16-
where TConnection : DataConnection
8+
public interface IConnectionFactory
179
{
1810
/// <summary>
1911
/// Gets new instance of <see cref="IDataContext" />
2012
/// </summary>
2113
/// <returns>
2214
/// <see cref="IDataContext" />
2315
/// </returns>
24-
TContext GetContext();
16+
IDataContext GetContext();
2517

2618
/// <summary>
2719
/// Gets new instance of <see cref="DataConnection" />
2820
/// </summary>
2921
/// <returns>
3022
/// <see cref="DataConnection" />
3123
/// </returns>
32-
TConnection GetConnection();
24+
DataConnection GetConnection();
3325
}
3426
}

src/LinqToDB.Identity/IdentityLinqToDbBuilderExtensions.cs

Lines changed: 94 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,77 +13,130 @@
1313
namespace Microsoft.Extensions.DependencyInjection
1414
{
1515
/// <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.
1717
/// </summary>
1818
public static class IdentityLinqToDbBuilderExtensions
1919
{
2020
/// <summary>
21-
/// Adds an Entity Framework implementation of identity information stores.
21+
/// Adds an linq2db plementation of identity information stores.
2222
/// </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>
3123
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
3224
/// <param name="factory">
33-
/// <see cref="IConnectionFactory{TContext,TConnection}" />
25+
/// <see cref="IConnectionFactory" />
3426
/// </param>
3527
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
3628
// 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)
4130
{
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+
}
4339

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>));
4760
}
4861

4962
/// <summary>
50-
/// Adds an Entity Framework implementation of identity information stores.
63+
/// Adds an linq2db implementation of identity information stores.
5164
/// </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>
6065
/// <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>
6171
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
6272
/// <param name="factory">
63-
/// <see cref="IConnectionFactory{TContext,TConnection}" />
73+
/// <see cref="IConnectionFactory" />
6474
/// </param>
6575
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
6676
// 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>
7188
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)
72118
{
73119
builder.Services.AddSingleton(factory);
74120

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+
76131
return builder;
77132
}
78133

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)
81135
{
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);
87140

88141
var services = new ServiceCollection();
89142
services.AddScoped(

src/LinqToDB.Identity/LinqToDB.Identity.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414
<PackageId>linq2db.Identity</PackageId>
1515
<PackageTags>aspnetcore;linq2db;identity;membership;LinqToDB</PackageTags>
1616
<PackageIconUrl>http://www.gravatar.com/avatar/fc2e509b6ed116b9aa29a7988fdb8990?s=320</PackageIconUrl>
17-
<PackageProjectUrl>https://github.com/ili/LinqToDB.Identity</PackageProjectUrl>
17+
<PackageProjectUrl>https://github.com/linq2db/LinqToDB.Identity</PackageProjectUrl>
1818
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
1919
<RepositoryType>git</RepositoryType>
20-
<RepositoryUrl>git://github.com/ili/LinqToDB.Identity</RepositoryUrl>
20+
<RepositoryUrl>git://github.com/linq2db/LinqToDB.Identity</RepositoryUrl>
2121
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
2222
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
2323
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
2424
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
2525
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
26+
<Version>1.2.0</Version>
2627
</PropertyGroup>
2728

2829
<ItemGroup>
@@ -31,7 +32,7 @@
3132

3233
<ItemGroup>
3334
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="1.1.2" />
34-
<PackageReference Include="linq2db.core" Version="1.8.0" />
35+
<PackageReference Include="linq2db.core" Version="1.8.3" />
3536
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
3637
</ItemGroup>
3738

src/LinqToDB.Identity/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
[assembly: AssemblyMetadata("Serviceable", "True")]
88
[assembly: NeutralResourcesLanguage("en-us")]
99
[assembly: AssemblyCompany("blog.linq2db.com")]
10-
[assembly: AssemblyCopyright("\xA9 2011-2016 blog.linq2db.com")]
10+
[assembly: AssemblyCopyright("© 2011-2017 blog.linq2db.com")]
1111
[assembly: AssemblyProduct("Linq to DB")]

0 commit comments

Comments
 (0)