![]() |
VOOZH | about |
dotnet add package MySqlConnector.DependencyInjection --version 2.6.0
NuGet\Install-Package MySqlConnector.DependencyInjection -Version 2.6.0
<PackageReference Include="MySqlConnector.DependencyInjection" Version="2.6.0" />
<PackageVersion Include="MySqlConnector.DependencyInjection" Version="2.6.0" />Directory.Packages.props
<PackageReference Include="MySqlConnector.DependencyInjection" />Project file
paket add MySqlConnector.DependencyInjection --version 2.6.0
#r "nuget: MySqlConnector.DependencyInjection, 2.6.0"
#:package MySqlConnector.DependencyInjection@2.6.0
#addin nuget:?package=MySqlConnector.DependencyInjection&version=2.6.0Install as a Cake Addin
#tool nuget:?package=MySqlConnector.DependencyInjection&version=2.6.0Install as a Cake Tool
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.
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...
});
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 */ })
);
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 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
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. |
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 | 2,687 | 6/2/2026 |
| 2.6.0-beta.2 | 56 | 5/26/2026 |
| 2.6.0-beta.1 | 66 | 5/25/2026 |
| 2.5.0 | 96,771 | 11/12/2025 |
| 2.4.0 | 273,044 | 11/12/2024 |
| 2.3.6 | 132,809 | 3/20/2024 |
| 2.3.5 | 41,101 | 1/20/2024 |
| 2.3.1 | 20,843 | 11/17/2023 |
| 2.3.0 | 1,033 | 11/14/2023 |