Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LinqToDB.Identity migration #3886

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<!--source-->
<PackageVersion Include="protobuf-net.Grpc" Version="1.0.179" />
<PackageVersion Include="Grpc.Net.Client" Version="2.50.0" />
<PackageVersion Include="Microsoft.Extensions.Identity.Stores" Version="7.0.1" />
<!--examples-->
<PackageVersion Include="linq2db.t4models" Version="4.3.0" />
<!--tests-->
Expand Down
2 changes: 2 additions & 0 deletions NuGet/Pack.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ IF [%1] EQU [snupkg] (
nuget.exe Pack ..\BuiltNuGet\linq2db.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
nuget.exe Pack ..\BuiltNuGet\linq2db.AspNet.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
nuget.exe Pack ..\BuiltNuGet\linq2db.Tools.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
nuget.exe Pack ..\BuiltNuGet\linq2db.Identity.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
nuget.exe Pack ..\BuiltNuGet\linq2db.Remote.Grpc.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
nuget.exe Pack ..\BuiltNuGet\linq2db.Remote.Wcf.nuspec -OutputDirectory ..\BuiltNuGet\built -Symbols -SymbolPackageFormat snupkg
) ELSE (
Expand All @@ -13,6 +14,7 @@ REM https://developercommunity.visualstudio.com/idea/657354/add-snupkg-support-t
nuget.exe Pack ..\BuiltNuGet\linq2db.nuspec -OutputDirectory ..\BuiltNuGet\built
nuget.exe Pack ..\BuiltNuGet\linq2db.AspNet.nuspec -OutputDirectory ..\BuiltNuGet\built
nuget.exe Pack ..\BuiltNuGet\linq2db.Tools.nuspec -OutputDirectory ..\BuiltNuGet\built
nuget.exe Pack ..\BuiltNuGet\linq2db.Identity.nuspec -OutputDirectory ..\BuiltNuGet\built
nuget.exe Pack ..\BuiltNuGet\linq2db.Remote.Grpc.nuspec -OutputDirectory ..\BuiltNuGet\built
nuget.exe Pack ..\BuiltNuGet\linq2db.Remote.Wcf.nuspec -OutputDirectory ..\BuiltNuGet\built
)
Expand Down
39 changes: 39 additions & 0 deletions NuGet/linq2db.Identity.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>linq2db.Identity</id>
<title>LINQ to DB ASP.NET Core Identity Provider</title>
<description>ASP.NET Core Identity provider that uses LinqToDB as data access layer.</description>
<summary />
<tags>aspnetcore linq2db identity membership LinqToDB</tags>
<readme>README.md</readme>
<dependencies>
<group targetFramework="net462" >
<dependency id="linq2db" version="4.0.0" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="7.0.1" />
</group>
<group targetFramework="netstandard2.0">
<dependency id="linq2db" version="4.0.0" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="7.0.1" />
</group>
<group targetFramework="net7.0" >
<dependency id="linq2db" version="4.0.0" />
<dependency id="Microsoft.Extensions.Identity.Stores" version="7.0.1" />
</group>
</dependencies>
</metadata>

<files>
<file src="..\Nuget\README.Identity.md" target="README.md" />

<file src="..\Source\LinqToDB.Identity\bin\Release\net462\linq2db.Identity.pdb" target="lib\net462\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\net462\linq2db.Identity.xml" target="lib\net462\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\net462\linq2db.Identity.dll" target="lib\net462\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\netstandard2.0\linq2db.Identity.pdb" target="lib\netstandard2.0\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\netstandard2.0\linq2db.Identity.xml" target="lib\netstandard2.0\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\netstandard2.0\linq2db.Identity.dll" target="lib\netstandard2.0\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\net7.0\linq2db.Identity.pdb" target="lib\net7.0\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\net7.0\linq2db.Identity.xml" target="lib\net7.0\" />
<file src="..\Source\LinqToDB.Identity\bin\Release\net7.0\linq2db.Identity.dll" target="lib\net7.0\" />
</files>
</package>
4 changes: 0 additions & 4 deletions Source/LinqToDB.AspNet/LinqToDB.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>

<AssemblyName>linq2db.AspNet</AssemblyName>
<RootNamespace>LinqToDB.AspNet</RootNamespace>
<TargetFrameworks>net45;netstandard2.0;net7.0</TargetFrameworks>

<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\linq2db.AspNet.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\LinqToDB\LinqToDB.csproj" />

<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
</ItemGroup>
Expand Down
42 changes: 42 additions & 0 deletions Source/LinqToDB.Identity/Context/IdentityDataConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using LinqToDB.Configuration;
using LinqToDB.Mapping;
using Microsoft.AspNetCore.Identity;

namespace LinqToDB.Identity
{
/// <summary>
/// Base class for the LinqToDB database context used for identity.
/// </summary>
public class IdentityDataConnection : IdentityDataConnection<IdentityUser, IdentityRole, string>
{
/// <summary>
/// Constructor with options.
/// </summary>
/// <param name="options">Connection options.</param>
//public IdentityDataConnection(DataOptions options)
public IdentityDataConnection(LinqToDBConnectionOptions options)
: base(options)
{
}

/// <summary>
/// Default constructor.
/// </summary>
public IdentityDataConnection()
{
}

protected override void ConfigureMappings(MappingSchema mappingSchema)
{
var builder = mappingSchema.GetFluentMappingBuilder();

DefaultMappings.SetupIdentityUser <IdentityUser >(builder);
DefaultMappings.SetupIdentityUserClaim<IdentityUserClaim<string>>(builder);
DefaultMappings.SetupIdentityUserLogin<IdentityUserLogin<string>>(builder);
DefaultMappings.SetupIdentityUserToken<IdentityUserToken<string>>(builder);
DefaultMappings.SetupIdentityRole <IdentityRole >(builder);
DefaultMappings.SetupIdentityUserRole <IdentityUserRole<string >>(builder);
DefaultMappings.SetupIdentityRoleClaim<IdentityRoleClaim<string>>(builder);
}
}
}
44 changes: 44 additions & 0 deletions Source/LinqToDB.Identity/Context/IdentityDataConnectionT1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using LinqToDB.Configuration;
using LinqToDB.Mapping;
using Microsoft.AspNetCore.Identity;

namespace LinqToDB.Identity
{
/// <summary>
/// Base class for the LinqToDB database context used for identity.
/// </summary>
/// <typeparam name="TUser">The type of the user objects.</typeparam>
public class IdentityDataConnection<TUser> : IdentityDataConnection<TUser, IdentityRole, string>
where TUser : IdentityUser
{
/// <summary>
/// Constructor with options.
/// </summary>
/// <param name="options">Connection options.</param>
//public IdentityDataConnection(DataOptions options)
public IdentityDataConnection(LinqToDBConnectionOptions options)
: base(options)
{
}

/// <summary>
/// Default constructor.
/// </summary>
public IdentityDataConnection()
{
}

protected override void ConfigureMappings(MappingSchema mappingSchema)
{
var builder = mappingSchema.GetFluentMappingBuilder();

DefaultMappings.SetupIdentityUser <TUser >(builder);
DefaultMappings.SetupIdentityUserClaim<IdentityUserClaim<string>>(builder);
DefaultMappings.SetupIdentityUserLogin<IdentityUserLogin<string>>(builder);
DefaultMappings.SetupIdentityUserToken<IdentityUserToken<string>>(builder);
DefaultMappings.SetupIdentityRole <IdentityRole >(builder);
DefaultMappings.SetupIdentityUserRole <IdentityUserRole<string >>(builder);
DefaultMappings.SetupIdentityRoleClaim<IdentityRoleClaim<string>>(builder);
}
}
}
36 changes: 36 additions & 0 deletions Source/LinqToDB.Identity/Context/IdentityDataConnectionT3.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using LinqToDB.Configuration;
using Microsoft.AspNetCore.Identity;

namespace LinqToDB.Identity
{
/// <summary>
/// Base class for the LinqToDB database context used for identity.
/// </summary>
/// <typeparam name="TUser">The type of user objects.</typeparam>
/// <typeparam name="TRole">The type of role objects.</typeparam>
/// <typeparam name="TKey">The type of the primary key for users and roles.</typeparam>
public class IdentityDataConnection<TUser, TRole, TKey> :
IdentityDataConnection<TUser, TRole, TKey, IdentityUserClaim<TKey>, IdentityUserRole<TKey>, IdentityUserLogin<TKey>, IdentityRoleClaim<TKey>, IdentityUserToken<TKey>>
where TUser : IdentityUser<TKey>
where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey>
{
/// <summary>
/// Constructor with options.
/// </summary>
/// <param name="options">Connection options.</param>
//public IdentityDataConnection(DataOptions options)
public IdentityDataConnection(LinqToDBConnectionOptions options)
: base(options)
{
}

/// <summary>
/// Default constructor.
/// </summary>
public IdentityDataConnection()
{
}
}
}
99 changes: 99 additions & 0 deletions Source/LinqToDB.Identity/Context/IdentityDataConnectionT5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
using System;
using LinqToDB.Configuration;
using LinqToDB.Data;
using LinqToDB.Mapping;
using Microsoft.AspNetCore.Identity;

namespace LinqToDB.Identity
{
/// <summary>
/// Base class for the LinqToDB database context used for identity.
/// </summary>
/// <typeparam name="TUser">The type of user objects.</typeparam>
/// <typeparam name="TKey">The type of the primary key for users and roles.</typeparam>
/// <typeparam name="TUserClaim">The type of the user claim object.</typeparam>
/// <typeparam name="TUserLogin">The type of the user login object.</typeparam>
/// <typeparam name="TUserToken">The type of the user token object.</typeparam>
public class IdentityDataConnection<TUser, TKey, TUserClaim, TUserLogin, TUserToken> :
DataConnection
where TUser : IdentityUser<TKey>
where TKey : IEquatable<TKey>
where TUserClaim : IdentityUserClaim<TKey>
where TUserLogin : IdentityUserLogin<TKey>
where TUserToken : IdentityUserToken<TKey>
{
private static readonly object _syncRoot = new ();
private static MappingSchema? _mappingSchema;

/// <summary>
/// Constructor with options.
/// </summary>
/// <param name="options">Connection options.</param>
//public IdentityDataConnection(DataOptions options)
public IdentityDataConnection(LinqToDBConnectionOptions options)
: base(options)
{
// TODO: rework after options merge
AddMappingSchema(GetMappingSchema());
}

/// <summary>
/// Default constructor.
/// </summary>
public IdentityDataConnection()
{
// TODO: rework after options merge
AddMappingSchema(GetMappingSchema());
}

private MappingSchema GetMappingSchema()
{
if (_mappingSchema == null)
{
lock (_syncRoot)
{
if (_mappingSchema == null)
{
var ms = new MappingSchema();

ConfigureMappings(ms);

_mappingSchema = ms;
}
}
}

return _mappingSchema;
}

protected virtual void ConfigureMappings(MappingSchema mappingSchema)
{
var builder = mappingSchema.GetFluentMappingBuilder();

DefaultMappings.SetupIdentityUser <TKey, TUser >(builder);
DefaultMappings.SetupIdentityUserClaim<TKey, TUserClaim>(builder);
DefaultMappings.SetupIdentityUserLogin<TKey, TUserLogin>(builder);
DefaultMappings.SetupIdentityUserToken<TKey, TUserToken>(builder);
}

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of Users.
/// </summary>
public ITable<TUser> Users => this.GetTable<TUser>();

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of User claims.
/// </summary>
public ITable<TUserClaim> UserClaims => this.GetTable<TUserClaim>();

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of User logins.
/// </summary>
public ITable<TUserLogin> UserLogins => this.GetTable<TUserLogin>();

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of User tokens.
/// </summary>
public ITable<TUserToken> UserTokens => this.GetTable<TUserToken>();
}
}
73 changes: 73 additions & 0 deletions Source/LinqToDB.Identity/Context/IdentityDataConnectionT8.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System;
using LinqToDB.Configuration;
using LinqToDB.Mapping;
using Microsoft.AspNetCore.Identity;

namespace LinqToDB.Identity
{
/// <summary>
/// Base class for the LinqToDB database context used for identity.
/// </summary>
/// <typeparam name="TUser">The type of user objects.</typeparam>
/// <typeparam name="TRole">The type of role objects.</typeparam>
/// <typeparam name="TKey">The type of the primary key for users and roles.</typeparam>
/// <typeparam name="TUserClaim">The type of the user claim object.</typeparam>
/// <typeparam name="TUserRole">The type of the user role object.</typeparam>
/// <typeparam name="TUserLogin">The type of the user login object.</typeparam>
/// <typeparam name="TRoleClaim">The type of the role claim object.</typeparam>
/// <typeparam name="TUserToken">The type of the user token object.</typeparam>
public class IdentityDataConnection<TUser, TRole, TKey, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken> :
IdentityDataConnection<TUser, TKey, TUserClaim, TUserLogin, TUserToken>
where TUser : IdentityUser<TKey>
where TRole : IdentityRole<TKey>
where TKey : IEquatable<TKey>
where TUserClaim : IdentityUserClaim<TKey>
where TUserRole : IdentityUserRole<TKey>
where TUserLogin : IdentityUserLogin<TKey>
where TRoleClaim : IdentityRoleClaim<TKey>
where TUserToken : IdentityUserToken<TKey>
{
/// <summary>
/// Constructor with options.
/// </summary>
/// <param name="options">Connection options.</param>
//public IdentityDataConnection(DataOptions options)
public IdentityDataConnection(LinqToDBConnectionOptions options)
: base(options)
{
}

/// <summary>
/// Default constructor.
/// </summary>
public IdentityDataConnection()
{
}

protected override void ConfigureMappings(MappingSchema mappingSchema)
{
base.ConfigureMappings(mappingSchema);

var builder = mappingSchema.GetFluentMappingBuilder();

DefaultMappings.SetupIdentityRole <TKey, TRole >(builder);
DefaultMappings.SetupIdentityUserRole <TKey, TUserRole >(builder);
DefaultMappings.SetupIdentityRoleClaim<TKey, TRoleClaim>(builder);
}

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of User roles.
/// </summary>
public ITable<TUserRole> UserRoles => this.GetTable<TUserRole>();

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of roles.
/// </summary>
public ITable<TRole> Roles => this.GetTable<TRole>();

/// <summary>
/// Gets the <see cref="ITable{TEntity}" /> of role claims.
/// </summary>
public ITable<TRoleClaim> RoleClaims => this.GetTable<TRoleClaim>();
}
}
Loading