MySqlConnector.DependencyInjection
2.6.0-beta.2
Prefix Reserved
See the version list below for details.
dotnet add package MySqlConnector.DependencyInjection --version 2.6.0-beta.2
NuGet\Install-Package MySqlConnector.DependencyInjection -Version 2.6.0-beta.2
<PackageReference Include="MySqlConnector.DependencyInjection" Version="2.6.0-beta.2" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.6.0-beta.2" />
<PackageReference Include="MySqlConnector.DependencyInjection" />
paket add MySqlConnector.DependencyInjection --version 2.6.0-beta.2
#r "nuget: MySqlConnector.DependencyInjection, 2.6.0-beta.2"
#:package MySqlConnector.DependencyInjection@2.6.0-beta.2
#addin nuget:?package=MySqlConnector.DependencyInjection&version=2.6.0-beta.2&prerelease
#tool nuget:?package=MySqlConnector.DependencyInjection&version=2.6.0-beta.2&prerelease
About
The dependency injection APIs from MySqlConnector.DependencyInjection are now included in MySqlConnector.
Uninstall MySqlConnector.DependencyInjection and use MySqlConnector instead.
dotnet remove package MySqlConnector.DependencyInjection
dotnet add package MySqlConnector
If MySqlConnector is already installed, only the dotnet remove package MySqlConnector.DependencyInjection command is needed.
How to Use
No code changes are required when switching packages. Continue using the same APIs from the MySqlConnector namespace:
using MySqlConnector;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default"));
This still registers a transient MySqlConnection which can get injected into your controllers:
app.MapGet("/", async (MySqlConnection connection) =>
{
await connection.OpenAsync();
await using var command = connection.CreateCommand();
command.CommandText = "SELECT name FROM users LIMIT 1";
return "Hello World: " + await command.ExecuteScalarAsync();
});
You can use MySqlDataSource directly if you need more than one connection:
app.MapGet("/", async (MySqlDataSource dataSource) =>
{
await using var connection1 = await dataSource.OpenConnectionAsync();
await using var connection2 = await dataSource.OpenConnectionAsync();
// use the two connections...
});
Advanced Usage
MySqlConnector still provides the same AddMySqlDataSource overloads for configuring aspects of MySqlConnector beyond the connection string.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMySqlDataSource("Server=server;User ID=test;Password=test;Database=test",
x => x.UseRemoteCertificateValidationCallback((sender, certificate, chain, sslPolicyErrors) => { /* custom logic */ })
);
Keyed Services
Use the AddKeyedMySqlDataSource method to register a MySqlDataSource as a keyed service.
This is useful if you have multiple connection strings or need to connect to multiple databases.
If the service key is a string, it will automatically be used as the MySqlDataSource name;
to customize this, call the AddKeyedMySqlDataSource(object?, string, Action<MySqlDataSourceBuilder>) overload and call MySqlDataSourceBuilder.UseName.
builder.Services.AddKeyedMySqlDataSource("users", builder.Configuration.GetConnectionString("Users"));
builder.Services.AddKeyedMySqlDataSource("products", builder.Configuration.GetConnectionString("Products"));
app.MapGet("/users/{userId}", async (int userId, [FromKeyedServices("users")] MySqlConnection connection) =>
{
await connection.OpenAsync();
await using var command = connection.CreateCommand();
command.CommandText = "SELECT name FROM users WHERE user_id = @userId LIMIT 1";
command.Parameters.AddWithValue("@userId", userId);
return $"Hello, {await command.ExecuteScalarAsync()}";
});
app.MapGet("/products/{productId}", async (int productId, [FromKeyedServices("products")] MySqlConnection connection) =>
{
await connection.OpenAsync();
await using var command = connection.CreateCommand();
command.CommandText = "SELECT name FROM products WHERE product_id = @productId LIMIT 1";
command.Parameters.AddWithValue("@productId", productId);
return await command.ExecuteScalarAsync();
});
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- MySqlConnector (>= 2.6.0-beta.2)
- System.Diagnostics.DiagnosticSource (>= 8.0.1)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- MySqlConnector (>= 2.6.0-beta.2)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on MySqlConnector.DependencyInjection:
| Package | Downloads |
|---|---|
|
Aspire.MySqlConnector
A MySQL client that integrates with Aspire, including health checks, metrics, logging, and telemetry. |
|
|
YakShaveFx.OutboxKit.MySql
Toolkit to assist in implementing the transactional outbox pattern. |
|
|
CodedThought.Core.Data.Sybase
The CodedThought.Core.Data.Sybase package is a custom database provider for use with a Sybase Server. |
GitHub repositories (3)
Showing the top 3 popular GitHub repositories that depend on MySqlConnector.DependencyInjection:
| Repository | Stars |
|---|---|
|
microsoft/aspire
Aspire is the tool for code-first, extensible, observable dev and deploy.
|
|
|
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
|
|
|
PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.6.0 | 0 | 6/2/2026 |
| 2.6.0-beta.2 | 45 | 5/26/2026 |
| 2.6.0-beta.1 | 60 | 5/25/2026 |
| 2.5.0 | 87,231 | 11/12/2025 |
| 2.4.0 | 265,482 | 11/12/2024 |
| 2.3.6 | 131,724 | 3/20/2024 |
| 2.3.5 | 40,471 | 1/20/2024 |
| 2.3.1 | 20,338 | 11/17/2023 |
| 2.3.0 | 903 | 11/14/2023 |