TH.DapperIdentity
1.0.5
dotnet add package TH.DapperIdentity --version 1.0.5
NuGet\Install-Package TH.DapperIdentity -Version 1.0.5
<PackageReference Include="TH.DapperIdentity" Version="1.0.5" />
<PackageVersion Include="TH.DapperIdentity" Version="1.0.5" />
<PackageReference Include="TH.DapperIdentity" />
paket add TH.DapperIdentity --version 1.0.5
#r "nuget: TH.DapperIdentity, 1.0.5"
#:package TH.DapperIdentity@1.0.5
#addin nuget:?package=TH.DapperIdentity&version=1.0.5
#tool nuget:?package=TH.DapperIdentity&version=1.0.5
DapperIdentity
Custom implementation of .NET Core Identity User and Role stores using Dapper.
Contains implementation of stores and interfaces for repositories which are used within stores.
This package also includes Sql Server implementation of said repositories.
To use different database provider, provide implementation of repository interfaces and pass them in the DI configuration.
Installing package
Install DapperIdentity with Package Manager Console using command
Install-Package TH.DapperIdentity
Or via .NET CLI using command
dotnet add package TH.DapperIdentity
Or just search for TH.DapperIdentity in Nuget Packages UI
Using DapperIdentity
DapperIdentity provides extension method AddDapperStores on top of IdentityBuilder object while configuring .NET Core Identity.
AddDapperStores method takes 3 parameters:
- Generic type parameter of class that implements IDbConnectionFactory (provided SqlServer factory or custom implementation for other database providers)
- Database connection string
- Delegate to configure DapperStoresOptions (implementation of repositories are added here)
Using provided Sql Server repositories:
services.AddIdentity<IdentityUser<int>, IdentityRole<int>>()
.AddDapperStores<SqlServerDbConnectionFactory>(connectionString, options =>
{
options.AddSqlServerIdentityRepositories<IdentityUser<int>, int>();
});
You can also set custom database table names through options:
services.AddIdentity<IdentityUser<int>, IdentityRole<int>>()
.AddDapperStores<SqlServerDbConnectionFactory>(connectionString, options =>
{
options.AddSqlServerIdentityRepositories<IdentityUser<int>, int>();
options.TableNames.UsersTableName = "Users";
options.TableNames.RolesTableName = "Roles";
options.TableNames.UserRolesTableName = "UserRoles";
options.TableNames.UserClaimsTableName = "UserClaims";
options.TableNames.RoleClaimsTableName = "RoleClaims";
options.TableNames.UserLoginsTableName = "UserLogins";
options.TableNames.UserTokensTableName = "UserTokens";
});
If you want to use custom implementation of repositories for different database provider you need to register them through options using extension methods:
services.AddIdentity<IdentityUser<int>, IdentityRole<int>>()
.AddDapperStores<SqlServerDbConnectionFactory>(connectionString, options =>
{
options.AddUserRepository<UserRepositoryImplementation, IdentityUser<int>, int>();
options.AddRoleRepository<RoleRepositoryImplementation, IdentityRole<int>, int>();
options.AddUserLoginRepository<UserLoginRepositoryImplementation, IdentityUser<int>, int>();
...
});
Keep in mind if you are not registering Role class with .NET Core Identity you should register only those repositories that don't use roles including UserOnlyRepository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Dapper (>= 2.1.44)
- Microsoft.Data.SqlClient (>= 5.2.0)
- Microsoft.Extensions.Identity.Stores (>= 8.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.