Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore
1.0.1
dotnet add package Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore --version 1.0.1
NuGet\Install-Package Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore -Version 1.0.1
<PackageReference Include="Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore" Version="1.0.1" />
paket add Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore --version 1.0.1
#r "nuget: Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore, 1.0.1"
// Install Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore as a Cake Addin #addin nuget:?package=Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore&version=1.0.1 // Install Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore as a Cake Tool #tool nuget:?package=Batec.Azure.Data.Extensions.Pomelo.EntityFrameworkCore&version=1.0.1
Authentication helper library for Azure Database for MySQL and Entity Framework Core
This library provides some extension methods to facilitate the usage of Azure AD authentication when connecting to Azure Database for MySQL.
Pomelo provides Entity Framework support for MySqlConnector.
DbContextOptionsBuilder extensions
DbContextOptionsBuilder is used to configure the Entity Framework context. Pomelo.EntityFrameworkCore.MySql library provides the UseMySql
method to configure MySql connections. This library provides some extensions to facilitate the configuration for MySql using Azure AD authentication.
This library uses Batec.Azure.Data.Extensions.MySqlConnector library to get an Azure AD access token that can be used to authenticate to MySql. It requires a TokenCredential, here some some options:
- Using DefaultAzureCredential. This component has a fallback mechanism trying to get an access token using different mechanisms. This is the default implementation.
- Specify an Azure Managed Identity. It uses DefaultAzureCredential, but tries to use a specific Managed Identity if the application hosting has more than one managed identity assigned.
- Specify another TokenCredential. It uses a TokenCredential provided by the caller to retrieve an access token.
Sample DefaultAzureCredential
It uses DefaultAzureCredential to get a token.
// Pomelo requires to specify the server version
ServerVersion serverVersion = ServerVersion.Parse("5.7", Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql);
// configuring services
var services = new ServiceCollection();
services.AddDbContextFactory<SampleContext>(options =>
{
options
.UseMySql("MYSQL CONNECTION STRING", serverVersion)
.UseAzureADAuthentication(new DefaultAzureCredential()); // Usage of this library
});
Sample with specific Managed Identity
It uses UseAzureADAuthentication passing a DefaultAzureCredential with the client id of the prefered managed identity in case the hosting service has more than one assigned. It uses DefaultAzureCredential passing the preferred managed identity.
// Pomelo requires to specify the server version
ServerVersion serverVersion = ServerVersion.Parse("5.7", Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql);
// configuring services
var services = new ServiceCollection();
string managedIdentityClientId = "00000000-0000-0000-000000000000";
services.AddDbContextFactory<SampleContext>(options =>
{
options
.UseMySql("MYSQL CONNECTION STRING", serverVersion)
.UseAzureADAuthentication(new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = managedIdentityClientId })); // Usage of this library
});
Sample using TokenCredential
It uses UseAzureADAuthentication passing a TokenCredential provided by the caller. For simplicity, this sample use AzureCliCredential
// Pomelo requires to specify the server version
ServerVersion serverVersion = ServerVersion.Parse("5.7", Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql);
// configuring services
var services = new ServiceCollection();
AzureCliCredential tokenCredential = new AzureCliCredential();
services.AddDbContextFactory<SampleContext>(options =>
{
options
.UseMySql("MYSQL CONNECTION STRING", serverVersion)
.UseAzureADAuthentication(tokenCredential)); // Usage of this library
});
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 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. |
-
net6.0
- Batec.Azure.Data.Extensions.MySqlConnector (>= 1.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 7.0.0)
-
net7.0
- Batec.Azure.Data.Extensions.MySqlConnector (>= 1.0.0)
- Pomelo.EntityFrameworkCore.MySql (>= 7.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.