Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore 1.0.1

dotnet add package Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore --version 1.0.1                
NuGet\Install-Package Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore -Version 1.0.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="Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore --version 1.0.1                
#r "nuget: Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore, 1.0.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 Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore as a Cake Addin
#addin nuget:?package=Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore&version=1.0.1

// Install Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore as a Cake Tool
#tool nuget:?package=Batec.Azure.Data.Extensions.Npgsql.EntityFrameworkCore&version=1.0.1                

Authentication helper library for Azure Database for Postgresql and Entity Framework Core

This library provides some extension methods to facilitate the usage of Azure AD authentication when connecting to Azure Database for Postgresql.

DbContextOptionsBuilder extensions

DbContextOptionsBuilder is used to configure the Entity Framework context. This library provides the UseAzureADAuthentication method to configure PostgreSQL connections.

This library uses Batec.Azure.Data.Extensions.Npgsql library to get an Azure AD access token that can be used to authenticate to Postgresql. This method expects a TokenCredential, here some examples that can be used:

  • 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 a TokenCredential. It uses a TokenCredential provided by the caller to retrieve an access token.

Sample using DefaultAzureCredential

Using DefaultAzureCredential to get a token.

// configuring services
var services = new ServiceCollection();
services.AddDbContextFactory<SampleContext>(options =>
{
    options.UseNpgsql("POSTGRESQL CONNECTION STRING",
        npgsqlOptions => npgsqlOptions.UseAzureADAuthentication(new DefaultAzureCredential())); // Usage of this library
});

Sample with specific Managed Identity

It uses UseAzureADAuthentication passing 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.

// configuring services
var services = new ServiceCollection();
string managedIdentityClientId = "00000000-0000-0000-000000000000";
services.AddDbContextFactory<SampleContext>(options =>
{
    options.UseNpgsql("POSTGRESQL CONNECTION STRING",
        npgsqlOptions => npgsqlOptions.UseAzureADAuthentication(new DefaultAzureCredential(new DefaultAzureCredentialOptions { ManagedIdentityClientId = managedIdentityClientId })));
});

Sample using AzureCliCredential

It uses UseAzureADAuthentication passing a TokenCredential provided by the caller. For simplicity, this sample use AzureCliCredential

// configuring services
AzureCliCredential tokenCredential = new AzureCliCredential();
var services = new ServiceCollection();
services.AddDbContextFactory<ChecklistContext>(options =>
{
    options.UseNpgsql("POSTGRESQL CONNECTION STRING",
        options => options.UseAzureADAuthentication(tokenCredential)); // Usage of this library
});
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.1 187 8/6/2023
1.0.0 205 7/28/2023