Skip to content

Commit

Permalink
Merge pull request #7 from linq2db/issues
Browse files Browse the repository at this point in the history
Issues
  • Loading branch information
ili authored Jul 6, 2017
2 parents 4f3ef98 + ce3bd45 commit 5c44f84
Show file tree
Hide file tree
Showing 22 changed files with 677 additions and 371 deletions.
2 changes: 1 addition & 1 deletion samples/IdentitySample.Mvc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void ConfigureServices(IServiceCollection services)
options.Cookies.ApplicationCookie.DataProtectionProvider =
DataProtectionProvider.Create(new DirectoryInfo("C:\\Github\\Identity\\artifacts"));
})
.AddLinqToDBStores(new DefaultConnectionFactory<DataContext, ApplicationDataConnection>())
.AddLinqToDBStores(new DefaultConnectionFactory())
.AddDefaultTokenProviders();

services.AddMvc();
Expand Down
3 changes: 1 addition & 2 deletions samples/IdentitySample.Mvc/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<dl>
<dt>Initialize ASP.NET Identity</dt>
<dd>
You can initialize ASP.NET Identity when the application starts. Since ASP.NET Identity is Entity Framework based in this sample,
you can create DatabaseInitializer which is configured to get called each time the app starts.
You can initialize ASP.NET Identity when the application starts.
<strong>Please look in App_Start\IdentityConfig.cs</strong>
This code shows the following
<ul>
Expand Down
16 changes: 6 additions & 10 deletions src/LinqToDB.Identity/DefaultConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@
namespace LinqToDB.Identity
{
/// <summary>
/// Represents default <see cref="IConnectionFactory{TContext,TConnection}" />
/// Represents default <see cref="IConnectionFactory" />
/// </summary>
/// <typeparam name="TContext">The type of the data getContext class used to access the store.</typeparam>
/// <typeparam name="TConnection">The type repewsenting database getConnection <see cref="DataConnection" /></typeparam>
public class DefaultConnectionFactory<TContext, TConnection> : IConnectionFactory<TContext, TConnection>
where TContext : class, IDataContext, new()
where TConnection : DataConnection, new()
public class DefaultConnectionFactory : IConnectionFactory
{
/// <summary>
/// Creates <see cref="DataConnection" /> with default parameters
/// </summary>
/// <returns>
/// <see cref="DataConnection" />
/// </returns>
public TConnection GetConnection()
public DataConnection GetConnection()
{
return new TConnection();
return new DataConnection();
}

/// <summary>
Expand All @@ -28,9 +24,9 @@ public TConnection GetConnection()
/// <returns>
/// <see cref="DataContext" />
/// </returns>
public TContext GetContext()
public IDataContext GetContext()
{
return new TContext();
return new DataContext();
}
}
}
14 changes: 3 additions & 11 deletions src/LinqToDB.Identity/IConnectionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,22 @@ namespace LinqToDB.Identity
/// <summary>
/// Represents connection factory
/// </summary>
/// <typeparam name="TContext">
/// <see cref="IDataContext" />
/// </typeparam>
/// <typeparam name="TConnection">
/// <see cref="DataConnection" />
/// </typeparam>
public interface IConnectionFactory<out TContext, out TConnection>
where TContext : IDataContext
where TConnection : DataConnection
public interface IConnectionFactory
{
/// <summary>
/// Gets new instance of <see cref="IDataContext" />
/// </summary>
/// <returns>
/// <see cref="IDataContext" />
/// </returns>
TContext GetContext();
IDataContext GetContext();

/// <summary>
/// Gets new instance of <see cref="DataConnection" />
/// </summary>
/// <returns>
/// <see cref="DataConnection" />
/// </returns>
TConnection GetConnection();
DataConnection GetConnection();
}
}
135 changes: 94 additions & 41 deletions src/LinqToDB.Identity/IdentityLinqToDbBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,77 +13,130 @@
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Contains extension methods to <see cref="IdentityBuilder" /> for adding entity framework stores.
/// Contains extension methods to <see cref="IdentityBuilder" /> for adding linq2db stores.
/// </summary>
public static class IdentityLinqToDbBuilderExtensions
{
/// <summary>
/// Adds an Entity Framework implementation of identity information stores.
/// Adds an linq2db plementation of identity information stores.
/// </summary>
/// <typeparam name="TContext">
/// The type of the class for <see cref="IDataContext" />,
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// </typeparam>
/// <typeparam name="TConnection">
/// The type of the class for <see cref="DataConnection" />,
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// </typeparam>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="factory">
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// <see cref="IConnectionFactory" />
/// </param>
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
// ReSharper disable once InconsistentNaming
public static IdentityBuilder AddLinqToDBStores<TContext, TConnection>(this IdentityBuilder builder,
IConnectionFactory<TContext, TConnection> factory)
where TContext : IDataContext
where TConnection : DataConnection
public static IdentityBuilder AddLinqToDBStores(this IdentityBuilder builder, IConnectionFactory factory)
{
builder.Services.AddSingleton(factory);
return AddLinqToDBStores(builder, factory,
typeof(string),
typeof(IdentityUserClaim<string>),
typeof(IdentityUserRole<string>),
typeof(IdentityUserLogin<string>),
typeof(IdentityUserToken<string>),
typeof(IdentityRoleClaim<string>));
}

builder.Services.TryAdd(
GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TConnection)));
return builder;
/// <summary>
/// Adds an linq2db implementation of identity information stores.
/// </summary>
/// <typeparam name="TKey">The type of the primary key used for the users and roles.</typeparam>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="factory">
/// <see cref="IConnectionFactory" />
/// </param>
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
// ReSharper disable once InconsistentNaming
public static IdentityBuilder AddLinqToDBStores<TKey>(this IdentityBuilder builder, IConnectionFactory factory)
where TKey : IEquatable<TKey>
{
return AddLinqToDBStores(builder, factory,
typeof(TKey),
typeof(IdentityUserClaim<TKey>),
typeof(IdentityUserRole<TKey>),
typeof(IdentityUserLogin<TKey>),
typeof(IdentityUserToken<TKey>),
typeof(IdentityRoleClaim<TKey>));
}

/// <summary>
/// Adds an Entity Framework implementation of identity information stores.
/// Adds an linq2db implementation of identity information stores.
/// </summary>
/// <typeparam name="TContext">
/// The type of the class for <see cref="IDataContext" />,
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// </typeparam>
/// <typeparam name="TConnection">
/// The type of the class for <see cref="DataConnection" />,
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// </typeparam>
/// <typeparam name="TKey">The type of the primary key used for the users and roles.</typeparam>
/// <typeparam name="TUserClaim">The type representing a claim.</typeparam>
/// <typeparam name="TUserRole">The type representing a user role.</typeparam>
/// <typeparam name="TUserLogin">The type representing a user external login.</typeparam>
/// <typeparam name="TUserToken">The type representing a user token.</typeparam>
/// <typeparam name="TRoleClaim">The type of the class representing a role claim.</typeparam>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="factory">
/// <see cref="IConnectionFactory{TContext,TConnection}" />
/// <see cref="IConnectionFactory" />
/// </param>
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
// ReSharper disable once InconsistentNaming
public static IdentityBuilder AddLinqToDBStores<TContext, TConnection, TKey>(this IdentityBuilder builder,
IConnectionFactory<TContext, TConnection> factory)
where TContext : IDataContext
where TConnection : DataConnection
public static IdentityBuilder AddLinqToDBStores<
TKey,
TUserClaim,
TUserRole,
TUserLogin,
TUserToken,
TRoleClaim>(this IdentityBuilder builder, IConnectionFactory factory)
where TUserClaim : class, IIdentityUserClaim<TKey>
where TUserRole : class, IIdentityUserRole<TKey>
where TUserLogin : class, IIdentityUserLogin<TKey>
where TUserToken : class, IIdentityUserToken<TKey>
where TKey : IEquatable<TKey>
where TRoleClaim : class, IIdentityRoleClaim<TKey>
{

return AddLinqToDBStores(builder, factory,
typeof(TKey),
typeof(TUserClaim),
typeof(TUserRole),
typeof(TUserLogin),
typeof(TUserToken),
typeof(TRoleClaim));
}

/// <summary>
/// Adds an linq2db implementation of identity information stores.
/// </summary>
/// <param name="builder">The <see cref="IdentityBuilder" /> instance this method extends.</param>
/// <param name="factory">
/// <see cref="IConnectionFactory" />
/// </param>
/// <param name="keyType">The type of the primary key used for the users and roles.</param>
/// <param name="userClaimType">The type representing a claim.</param>
/// <param name="userRoleType">The type representing a user role.</param>
/// <param name="userLoginType">The type representing a user external login.</param>
/// <param name="userTokenType">The type representing a user token.</param>
/// <param name="roleClaimType">The type of the class representing a role claim.</param>
/// <returns>The <see cref="IdentityBuilder" /> instance this method extends.</returns>
// ReSharper disable once InconsistentNaming
public static IdentityBuilder AddLinqToDBStores(this IdentityBuilder builder, IConnectionFactory factory,
Type keyType, Type userClaimType, Type userRoleType, Type userLoginType, Type userTokenType, Type roleClaimType)
{
builder.Services.AddSingleton(factory);

builder.Services.TryAdd(GetDefaultServices(builder.UserType, builder.RoleType, typeof(TContext), typeof(TConnection), typeof(TKey)));
builder.Services.TryAdd(GetDefaultServices(
keyType,
builder.UserType,
userClaimType,
userRoleType,
userLoginType,
userTokenType,
builder.RoleType,
roleClaimType));

return builder;
}

private static IServiceCollection GetDefaultServices(Type userType, Type roleType, Type contextType,
Type connectionType, Type keyType = null)
private static IServiceCollection GetDefaultServices(Type keyType, Type userType, Type userClaimType, Type userRoleType, Type userLoginType, Type userTokenType, Type roleType, Type roleClaimType)
{
Type userStoreType;
Type roleStoreType;
keyType = keyType ?? typeof(string);
userStoreType = typeof(UserStore<,,,,>).MakeGenericType(contextType, connectionType, userType, roleType, keyType);
roleStoreType = typeof(RoleStore<,,,>).MakeGenericType(contextType, connectionType, roleType, keyType);
//UserStore<TKey, TUser, TRole, TUserClaim, TUserRole, TUserLogin, TUserToken>
var userStoreType = typeof(UserStore<,,,,,,>).MakeGenericType(keyType, userType, roleType, userClaimType, userRoleType, userLoginType, userTokenType);
// RoleStore<TKey, TRole, TRoleClaim>
var roleStoreType = typeof(RoleStore<,,>).MakeGenericType(keyType, roleType, roleClaimType);

var services = new ServiceCollection();
services.AddScoped(
Expand Down
7 changes: 4 additions & 3 deletions src/LinqToDB.Identity/LinqToDB.Identity.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
<PackageId>linq2db.Identity</PackageId>
<PackageTags>aspnetcore;linq2db;identity;membership;LinqToDB</PackageTags>
<PackageIconUrl>http://www.gravatar.com/avatar/fc2e509b6ed116b9aa29a7988fdb8990?s=320</PackageIconUrl>
<PackageProjectUrl>https://github.com/ili/LinqToDB.Identity</PackageProjectUrl>
<PackageProjectUrl>https://github.com/linq2db/LinqToDB.Identity</PackageProjectUrl>
<PackageLicenseUrl>https://opensource.org/licenses/MIT</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/ili/LinqToDB.Identity</RepositoryUrl>
<RepositoryUrl>git://github.com/linq2db/LinqToDB.Identity</RepositoryUrl>
<NetStandardImplicitPackageVersion>1.6.1</NetStandardImplicitPackageVersion>
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyCopyrightAttribute>false</GenerateAssemblyCopyrightAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<Version>1.2.0</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -31,7 +32,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="1.1.2" />
<PackageReference Include="linq2db.core" Version="1.8.0" />
<PackageReference Include="linq2db.core" Version="1.8.3" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="1.1.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/LinqToDB.Identity/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
[assembly: AssemblyMetadata("Serviceable", "True")]
[assembly: NeutralResourcesLanguage("en-us")]
[assembly: AssemblyCompany("blog.linq2db.com")]
[assembly: AssemblyCopyright("\xA9 2011-2016 blog.linq2db.com")]
[assembly: AssemblyCopyright("© 2011-2017 blog.linq2db.com")]
[assembly: AssemblyProduct("Linq to DB")]
Loading

0 comments on commit 5c44f84

Please sign in to comment.