Net4x.DapperLibrary.Extensions.DependencyInjection
1.9.9.26270
See the version list below for details.
dotnet add package Net4x.DapperLibrary.Extensions.DependencyInjection --version 1.9.9.26270
NuGet\Install-Package Net4x.DapperLibrary.Extensions.DependencyInjection -Version 1.9.9.26270
<PackageReference Include="Net4x.DapperLibrary.Extensions.DependencyInjection" Version="1.9.9.26270" />
<PackageVersion Include="Net4x.DapperLibrary.Extensions.DependencyInjection" Version="1.9.9.26270" />
<PackageReference Include="Net4x.DapperLibrary.Extensions.DependencyInjection" />
paket add Net4x.DapperLibrary.Extensions.DependencyInjection --version 1.9.9.26270
#r "nuget: Net4x.DapperLibrary.Extensions.DependencyInjection, 1.9.9.26270"
#:package Net4x.DapperLibrary.Extensions.DependencyInjection@1.9.9.26270
#addin nuget:?package=Net4x.DapperLibrary.Extensions.DependencyInjection&version=1.9.9.26270
#tool nuget:?package=Net4x.DapperLibrary.Extensions.DependencyInjection&version=1.9.9.26270
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
IDapperContextFactoryas a singleton (usesDapperContextFactory.Instance). - Registers an
IDapperContextas a scoped service created via the factory. - Reads connection strings from configuration sections:
ConnectionStrings� simple name ? connection stringConnectionStringsWithProvider� each child can containConnectionStringandProviderName
- Supports controlling when connections are closed via the
CloseConnectionparameter.
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.
- Simple connection strings (standard pattern):
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=MyDb;Trusted_Connection=True;",
"ReadOnly": "Server=.;Database=MyDb_Read;Trusted_Connection=True;"
}
- 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:
IDapperContextFactoryas a singleton (backed byDapperContextFactory.Instance).IDapperContextas scoped, created via the factory and configured with thecloseConnectionbehavior.
Notes
- The project relies on other library types such as
DapperConnectionStringSettings,DapperConfigurationManager,IDapperContext,IDapperContextFactoryandDapperContextFactory. 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 | Versions 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. |
-
.NETFramework 3.5
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
- Net4x.Extensions.Configuration.Json (>= 2.5.0.7)
-
.NETFramework 4.0
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
- Net4x.Extensions.Configuration.Json (>= 2.5.0.7)
-
.NETFramework 4.5
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
- Net4x.Extensions.Configuration.Json (>= 2.5.0.7)
-
.NETFramework 4.6.1
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
-
net10.0
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
-
net6.0
- Microsoft.Extensions.Configuration (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Net4x.DapperLibrary.Base (>= 1.9.9.26270)
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 |