Net4x.DapperLibrary.Extensions.DependencyInjection 1.9.9.26263

There is a newer version of this package available.
See the version list below for details.
dotnet add package Net4x.DapperLibrary.Extensions.DependencyInjection --version 1.9.9.26263
                    
NuGet\Install-Package Net4x.DapperLibrary.Extensions.DependencyInjection -Version 1.9.9.26263
                    
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="Net4x.DapperLibrary.Extensions.DependencyInjection" Version="1.9.9.26263" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Net4x.DapperLibrary.Extensions.DependencyInjection" Version="1.9.9.26263" />
                    
Directory.Packages.props
<PackageReference Include="Net4x.DapperLibrary.Extensions.DependencyInjection" />
                    
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 Net4x.DapperLibrary.Extensions.DependencyInjection --version 1.9.9.26263
                    
#r "nuget: Net4x.DapperLibrary.Extensions.DependencyInjection, 1.9.9.26263"
                    
#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 Net4x.DapperLibrary.Extensions.DependencyInjection@1.9.9.26263
                    
#: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=Net4x.DapperLibrary.Extensions.DependencyInjection&version=1.9.9.26263
                    
Install as a Cake Addin
#tool nuget:?package=Net4x.DapperLibrary.Extensions.DependencyInjection&version=1.9.9.26263
                    
Install as a Cake Tool

DapperLibrary.Extensions.DependencyInjection

Dependency injection helpers and extensions for wiring up Dapper-based IDapperContext instances and the IDapperContextFactory in an application's DI container.

This small library provides extension methods to register Dapper context services and to load connection string settings from application configuration.

Features

  • Registers the IDapperContextFactory as a singleton (uses DapperContextFactory.Instance).
  • Registers an IDapperContext as a scoped service created via the factory.
  • Reads connection strings from configuration sections:
    • ConnectionStrings � simple name ? connection string
    • ConnectionStringsWithProvider � each child can contain ConnectionString and ProviderName
  • Supports controlling when connections are closed via the CloseConnection parameter.

Supported targets

This project is intended to be multi-targeted for older .NET Framework versions and modern .NET (the code contains compilation conditionals). Use the version appropriate for your application framework.

Installation

Add a project reference to DapperLibrary.Extensions.DependencyInjection or install the package (if published) into your project.

Usage

In .NET 8+ hosted apps

If you are using the new host builder (.NET 8+), call the host builder convenience method:

// Program.cs (top-level)
var builder = Host.CreateApplicationBuilder(args);

// registers DI and reads configuration
builder.UseDapperContext();

var app = builder.Build();

You can also pass a CloseConnection value to control how connections are closed:

builder.UseDapperContext(CloseConnection.WhenDataReaderCloses);

In other apps (IServiceCollection)

Call the extension on IServiceCollection and pass your application's IConfiguration (or ConfigurationManager where supported):

public void ConfigureServices(IServiceCollection services)
{
    services.UseDapperContext(Configuration);
}

Or with an explicit CloseConnection value:

services.UseDapperContext(Configuration, CloseConnection.WhenCommandCompletes);

Configuration

The extension loads connection strings from configuration. Two patterns are supported.

  1. Simple connection strings (standard pattern):
"ConnectionStrings": {
  "DefaultConnection": "Server=.;Database=MyDb;Trusted_Connection=True;",
  "ReadOnly": "Server=.;Database=MyDb_Read;Trusted_Connection=True;"
}
  1. Complex connection strings with provider name:
"ConnectionStringsWithProvider": {
  "OracleConn": {
    "ConnectionString": "Data Source=...;User Id=...;Password=...;",
    "ProviderName": "Oracle.ManagedDataAccess.Client"
  }
}

The library will enumerate both sections and build DapperConnectionStringSettings entries for each child.

API reference (key entry points)

  • DapperContextExtension.UseDapperContext(this IServiceCollection services, IConfiguration configuration, CloseConnection closeConnection = CloseConnection.WhenDataReaderCloses)
  • DapperContextExtension.UseDapperContext(this IHostApplicationBuilder builder, CloseConnection closeConnection = CloseConnection.WhenDataReaderCloses) (available on .NET 8+ builds)

These methods register:

  • IDapperContextFactory as a singleton (backed by DapperContextFactory.Instance).
  • IDapperContext as scoped, created via the factory and configured with the closeConnection behavior.

Notes

  • The project relies on other library types such as DapperConnectionStringSettings, DapperConfigurationManager, IDapperContext, IDapperContextFactory and DapperContextFactory. Ensure those assemblies are available in the consuming solution.
  • Conditional compilation in the source supports multiple target frameworks; the visible extension overloads vary depending on the target framework.

Contributing

Contributions are welcome via pull requests. Keep changes small and add tests where appropriate.

License

See the repository license file.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 is compatible.  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. 
.NET Framework net35 is compatible.  net40 is compatible.  net403 was computed.  net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 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.9.9.26271 108 9/28/2026
1.9.9.26270 100 9/27/2026
1.9.9.26263 117 9/20/2026