TCIS.Persistence.Dapper 1.0.0-rc.9

This is a prerelease version of TCIS.Persistence.Dapper.
dotnet add package TCIS.Persistence.Dapper --version 1.0.0-rc.9
                    
NuGet\Install-Package TCIS.Persistence.Dapper -Version 1.0.0-rc.9
                    
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="TCIS.Persistence.Dapper" Version="1.0.0-rc.9" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TCIS.Persistence.Dapper" Version="1.0.0-rc.9" />
                    
Directory.Packages.props
<PackageReference Include="TCIS.Persistence.Dapper" />
                    
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 TCIS.Persistence.Dapper --version 1.0.0-rc.9
                    
#r "nuget: TCIS.Persistence.Dapper, 1.0.0-rc.9"
                    
#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 TCIS.Persistence.Dapper@1.0.0-rc.9
                    
#: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=TCIS.Persistence.Dapper&version=1.0.0-rc.9&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=TCIS.Persistence.Dapper&version=1.0.0-rc.9&prerelease
                    
Install as a Cake Tool

TCIS.Persistence.Dapper

The library providing an abstraction layer to work with Dapper safely and optimally within the TCIS ecosystem. It supports automatic DbConnection management via the Factory pattern and provides IDapperContext with numerous utility methods.

📦 Installation

dotnet add package TCIS.Persistence.Dapper

⚙️ Configuration (appsettings.json)

Shares configuration with other Persistence modules via the ConfigurationStore section:

{
  "ConfigurationStore": {
    "ConnectionString": "Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;",
    // ReadConnectionString will be prioritized for Query tasks if present
    "ReadConnectionString": "Server=myReadReplica;Database=myDataBase;User Id=myUsername;Password=myPassword;"
  }
}

🚀 Registration / Setup (Program.cs)

Note: If you are using the TCIS.Persistence.EntityFrameworkCore library, the AddTCorePersistence method automatically registers this library, so manual registration is not required.

If registering independently, you need to configure IDbConnectionFactory and IDapperContext:

using TCIS.Persistence.Data;
using TCIS.Persistence.Dapper;
using System.Data.SqlClient;

var builder = WebApplication.CreateBuilder(args);

// 1. Configure Options
builder.Services.AddOptions<PersistenceOptions>()
    .Bind(builder.Configuration.GetSection("ConfigurationStore"));

// 2. Register the Connection Factory
builder.Services.AddScoped<IDbConnectionFactory>(sp => 
    new DefaultDbConnectionFactory(
        sp.GetRequiredService<IOptions<PersistenceOptions>>(), 
        connectionString => new SqlConnection(connectionString)));

// 3. Register the Dapper Context
builder.Services.AddScoped<IDapperContext, DapperContext>();

💡 Usage

Inject IDapperContext into your code (Repository, Service, CQS Handlers).

using TCIS.Persistence.Dapper;

public class ReportService
{
    private readonly IDapperContext _dapperContext;

    public ReportService(IDapperContext dapperContext)
    {
        _dapperContext = dapperContext;
    }

    public async Task<IEnumerable<ReportDto>> GetDailyReportAsync(DateTime date)
    {
        string sql = "SELECT * FROM Reports WHERE ReportDate = @Date";
        
        // The factory will automatically open the connection, execute the query, and safely dispose of the connection
        return await _dapperContext.QueryAsync<ReportDto>(sql, new { Date = date });
    }
    
    public async Task<PagedResult<UserDto>> GetUsersPagedAsync(int pageIndex, int pageSize)
    {
        string countSql = "SELECT COUNT(1) FROM Users";
        string dataSql = "SELECT * FROM Users ORDER BY Id OFFSET @Offset ROWS FETCH NEXT @PageSize ROWS ONLY";
        
        // Supports automatic paginated querying
        return await _dapperContext.QueryPageAsync<UserDto>(
            countSql, 
            dataSql, 
            pageIndex, 
            pageSize, 
            new { Offset = (pageIndex - 1) * pageSize, PageSize = pageSize });
    }
}

Key Features:

  • DefaultDbConnectionFactory: Automatically provisions connections and provides automatic fallback/switching between ConnectionString and ReadConnectionString (for Queries).
  • Automatic Pagination: Provides the QueryPageAsync<T> method that prepares a PagedResult<T> out-of-the-box.
  • Query / Execute: Offers QueryAsync, ExecuteAsync, QuerySingleOrDefaultAsync, QueryFirstOrDefaultAsync similar to native Dapper but with safely managed connection lifecycles.
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 (1)

Showing the top 1 NuGet packages that depend on TCIS.Persistence.Dapper:

Package Downloads
TCIS.Persistence.EntityFrameworkCore

TCIS Core Framework is an application framework for building modular, multi-tenant applications on ASP.NET Core. Core Persistence EntityFrameworkCore implementation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-rc.9 25 7/21/2026
1.0.0-rc.8 26 7/21/2026
1.0.0-rc.7 54 7/17/2026