MySqlConnector.DependencyInjection 2.3.0-beta.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This is a prerelease version of MySqlConnector.DependencyInjection.
There is a newer version of this package available.
See the version list below for details.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package MySqlConnector.DependencyInjection --version 2.3.0-beta.1
NuGet\Install-Package MySqlConnector.DependencyInjection -Version 2.3.0-beta.1
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="MySqlConnector.DependencyInjection" Version="2.3.0-beta.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MySqlConnector.DependencyInjection --version 2.3.0-beta.1
#r "nuget: MySqlConnector.DependencyInjection, 2.3.0-beta.1"
#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.
// Install MySqlConnector.DependencyInjection as a Cake Addin
#addin nuget:?package=MySqlConnector.DependencyInjection&version=2.3.0-beta.1&prerelease

// Install MySqlConnector.DependencyInjection as a Cake Tool
#tool nuget:?package=MySqlConnector.DependencyInjection&version=2.3.0-beta.1&prerelease

About

MySqlConnector.DependencyInjection helps set up MySqlConnector in applications that use dependency injection, most notably in ASP.NET. It allows easy configuration of your MySQL connections and registers the appropriate services in your DI container.

How to Use

For example, if using the ASP.NET minimal web API, use the following to register MySqlConnector:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMySqlDataSource("Server=server;User ID=test;Password=test;Database=test");

This 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

The AddMySqlDataSource method also accepts a lambda parameter allowing you to configure 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 */ })
);
Product 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 is compatible.  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 was computed.  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. 
.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. 
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 MySqlConnector.DependencyInjection:

Package Downloads
Aspire.MySqlConnector The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org.

A MySQL client that integrates with Aspire, including health checks, metrics, logging, and telemetry.

GitHub repositories (3)

Showing the top 3 popular GitHub repositories that depend on MySqlConnector.DependencyInjection:

Repository Stars
Xabaril/AspNetCore.Diagnostics.HealthChecks
Enterprise HealthChecks for ASP.NET Core Diagnostics Package
dotnet/aspire
An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
PomeloFoundation/Pomelo.EntityFrameworkCore.MySql
Entity Framework Core provider for MySQL and MariaDB built on top of MySqlConnector
Version Downloads Last updated
2.3.6 3,468 3/20/2024
2.3.5 11,751 1/20/2024
2.3.1 10,402 11/17/2023
2.3.0 327 11/14/2023