Skip to content

Latest commit

Β 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ AdaskoTheBeAsT.Identity.Dapper

License NuGet SDK Target

Compile-time ASP.NET Core Identity stores for Dapper.

If you like ASP.NET Core Identity but do not want EF Core in the store layer, this repository gives you source-generated stores and SQL for SQL Server, PostgreSQL, MySQL, Oracle, and SQLite.

✨ Why developers like it

  • ⚑ Fast runtime path powered by Dapper
  • 🧠 Source-generated stores and provider-specific SQL instead of hand-written plumbing
  • 🧩 Works with string, int, long, and Guid keys
  • πŸ—οΈ Supports custom Identity properties and custom column names
  • πŸ—„οΈ Covers SQL Server, PostgreSQL, MySQL, Oracle, and SQLite
  • πŸŽ›οΈ Lets you skip normalized columns when you do not need them
  • πŸ§ͺ Backed by provider-specific unit and integration tests

πŸ—„οΈ Supported providers

Provider NuGet package Default schema Extra startup step
SQL Server AdaskoTheBeAsT.Identity.Dapper.SqlServer dbo none
PostgreSQL AdaskoTheBeAsT.Identity.Dapper.PostgreSql public PostgreSqlDapperConfig.ConfigureTypeHandlers();
MySQL AdaskoTheBeAsT.Identity.Dapper.MySql n/a MySqlDapperConfig.ConfigureTypeHandlers();
Oracle AdaskoTheBeAsT.Identity.Dapper.Oracle empty by default OracleDapperConfig.ConfigureTypeHandlers();
SQLite AdaskoTheBeAsT.Identity.Dapper.Sqlite n/a SQLitePCL.Batteries.Init(); and SqliteDapperConfig.ConfigureTypeHandlers();

The shared runtime package is AdaskoTheBeAsT.Identity.Dapper; most applications install a provider package and let that pull in the core runtime.

⚑ Quick start

1. Install the provider package you need

# SQL Server
dotnet add package AdaskoTheBeAsT.Identity.Dapper.SqlServer

# PostgreSQL
dotnet add package AdaskoTheBeAsT.Identity.Dapper.PostgreSql

# MySQL
dotnet add package AdaskoTheBeAsT.Identity.Dapper.MySql

# Oracle
dotnet add package AdaskoTheBeAsT.Identity.Dapper.Oracle

# SQLite
dotnet add package AdaskoTheBeAsT.Identity.Dapper.Sqlite

2. Define your Identity types

using System.ComponentModel.DataAnnotations.Schema;
using AdaskoTheBeAsT.Identity.Dapper.Attributes;
using Microsoft.AspNetCore.Identity;

namespace MyApp.Identity;

public sealed class ApplicationRole : IdentityRole<Guid>
{
}

public sealed class ApplicationRoleClaim : IdentityRoleClaim<Guid>
{
}

[InsertOwnId]
public sealed class ApplicationUser : IdentityUser<Guid>
{
    [Column("IsActive")]
    public bool IsActive { get; set; }
}

public sealed class ApplicationUserClaim : IdentityUserClaim<Guid>
{
}

public sealed class ApplicationUserLogin : IdentityUserLogin<Guid>
{
}

public sealed class ApplicationUserRole : IdentityUserRole<Guid>
{
}

public sealed class ApplicationUserToken : IdentityUserToken<Guid>
{
}

[InsertOwnId] is optional and useful when you want to keep external identity IDs unchanged.

3. Add optional MSBuild settings

Provider packages already ship sensible defaults. Add overrides only when you need them:

<PropertyGroup>
  <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
  <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
  <AdaskoTheBeAsTIdentityDapper_SkipNormalized>false</AdaskoTheBeAsTIdentityDapper_SkipNormalized>
  <AdaskoTheBeAsTIdentityDapper_DbSchema>dbo</AdaskoTheBeAsTIdentityDapper_DbSchema>
</PropertyGroup>

4. Register the connection provider and Identity stores

The example below uses SQL Server, but the pattern is the same for other providers.

using AdaskoTheBeAsT.Identity.Dapper.Abstractions;
using Microsoft.AspNetCore.Identity;
using Microsoft.Data.SqlClient;

builder.Services.AddSingleton<IIdentityDbConnectionProvider<SqlConnection>, IdentityDbConnectionProvider>();

builder.Services.AddIdentity<ApplicationUser, ApplicationRole>()
    .AddUserStore<ApplicationUserStore>()
    .AddRoleStore<ApplicationRoleStore>()
    .AddDefaultTokenProviders();

public sealed class IdentityDbConnectionProvider : IIdentityDbConnectionProvider<SqlConnection>
{
    private readonly IConfiguration _configuration;

    public IdentityDbConnectionProvider(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    public SqlConnection Provide() => new(_configuration.GetConnectionString("DefaultConnection")!);
}

ApplicationUserStore, ApplicationUserOnlyStore, and ApplicationRoleStore are generated during build.

5. Build once to generate the stores

dotnet build

If EmitCompilerGeneratedFiles is enabled, generated files are written to the folder configured by CompilerGeneratedFilesOutputPath.

6. Create the database schema

This library generates store code and SQL access logic, but it does not create your database schema for you.

Use the scripts in db/:

  • db/SqlServer/ contains SSDT-style .sqlproj schema projects
  • db/PostgreSQL/, db/MySql/, db/Oracle/, and db/SQLite/ contain SQL scripts
  • scripts are available for string, int, bigint, and Guid keys
  • each provider includes normalized and WithoutNormalized... variants

βš™οΈ Configuration reference

Property Default Applies to What it changes
EmitCompilerGeneratedFiles false all providers writes generated code to disk
CompilerGeneratedFilesOutputPath Generated all providers changes the generated output folder
AdaskoTheBeAsTIdentityDapper_SkipNormalized false all providers skips normalized role and user columns
AdaskoTheBeAsTIdentityDapper_DbSchema dbo / public / empty SQL Server, PostgreSQL, Oracle changes the schema prefix used by generated SQL
AdaskoTheBeAsTIdentityDapper_StoreBooleanAs char Oracle only stores booleans as char, number, or string

Provider notes

  • PostgreSQL: call PostgreSqlDapperConfig.ConfigureTypeHandlers();
  • MySQL: call MySqlDapperConfig.ConfigureTypeHandlers();
  • Oracle: call OracleDapperConfig.ConfigureTypeHandlers();
  • SQLite: call SQLitePCL.Batteries.Init(); and SqliteDapperConfig.ConfigureTypeHandlers();

πŸ“š Examples and useful docs

πŸ› οΈ Local development

Prerequisites

  • .NET SDK 10.0.201 (pinned in global.json)
  • Docker Desktop / Docker Engine for integration tests
  • PowerShell for clean.ps1
  • Visual Studio + SSDT if you need to edit SQL Server .sqlproj database projects

Handy commands

# restore everything
dotnet restore AdaskoTheBeAsT.Identity.Dapper.sln

# recommended filtered build loop
dotnet build WithoutSqlDb.slnf

# focused MySQL loop
dotnet build MySQL.slnf

# run the Web API sample
dotnet run --project src/AdaskoTheBeAsT.Identity.Dapper.WebApi/AdaskoTheBeAsT.Identity.Dapper.WebApi.csproj

# run a provider unit snapshot test project
dotnet test test/unit/AdaskoTheBeAsT.Identity.Dapper.PostgreSql.Test/AdaskoTheBeAsT.Identity.Dapper.PostgreSql.Test.csproj

# run a provider integration test project (Docker required)
dotnet test test/integ/AdaskoTheBeAsT.Identity.Dapper.Sqlite.IntegrationTest/AdaskoTheBeAsT.Identity.Dapper.Sqlite.IntegrationTest.csproj

# clean bin/obj folders
pwsh ./clean.ps1

🧭 Repository map

src/
  AdaskoTheBeAsT.Identity.Dapper/            shared runtime abstractions and base store types
  AdaskoTheBeAsT.Identity.Dapper.SqlServer/  SQL Server source generator package
  AdaskoTheBeAsT.Identity.Dapper.PostgreSql/ PostgreSQL source generator package
  AdaskoTheBeAsT.Identity.Dapper.MySql/      MySQL source generator package
  AdaskoTheBeAsT.Identity.Dapper.Oracle/     Oracle source generator package
  AdaskoTheBeAsT.Identity.Dapper.Sqlite/     SQLite source generator package
  AdaskoTheBeAsT.Identity.Dapper.WebApi/     runnable example app

db/        schema scripts and SQL Server schema projects
samples/   consumer samples and provider-specific notes
test/      provider unit snapshot tests and integration tests

🀝 Contributing

Pull requests are welcome. A good contributor loop is:

  1. build the relevant solution filter (WithoutSqlDb.slnf or MySQL.slnf)
  2. run the provider test project you touched
  3. keep generated SQL and snapshots aligned with the implementation

πŸ“„ License

This project is licensed under the MIT License.

πŸ’¬ Support

If this library saves you time, a GitHub star is always appreciated.

About

Dapper implementation for Microsoft.Extensions.Identity.Stores

Resources

Stars

12 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages