TH.DapperIdentity 1.0.5

dotnet add package TH.DapperIdentity --version 1.0.5
                    
NuGet\Install-Package TH.DapperIdentity -Version 1.0.5
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TH.DapperIdentity" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TH.DapperIdentity" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="TH.DapperIdentity" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TH.DapperIdentity --version 1.0.5
                    
#r "nuget: TH.DapperIdentity, 1.0.5"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TH.DapperIdentity@1.0.5
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TH.DapperIdentity&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=TH.DapperIdentity&version=1.0.5
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5 273 4/18/2024
1.0.4 221 4/15/2024
1.0.3 234 4/14/2024
1.0.2 235 4/13/2024
1.0.1 214 4/8/2024
1.0.0 531 11/30/2023