Using PostgreSQL with .NET and Entra ID

Table of Contents
- Getting started with PostgreSQL
- Adding PostgreSQL to the API
- Managing access tokens with Entra ID
- Next Steps
Getting started with PostgreSQL
- Create a new application using PostgreSQL as the database.
- Add the PostgreSQL hosting component to the AppHost project.
- Create a PostgreSQL resource and add it as a reference to the API project.
Adding PostgreSQL to the API
- Add the Npgsql package to the API project.
- Use the .NET Aspire package for logging and telemetry.
- Interact with the PostgreSQL database in the API project.
Managing access tokens with Entra ID
- Request an access token to act in place of a persistent password.
- Use the
Microsoft.Authentication.TokenCache
package to request access tokens. - Configure the
NpgsqlConnectionStringBuilder
to request new access tokens when needed.
Next Steps
Explore more advanced features of PostgreSQL in .NET and learn how to secure your application with Entra ID for Managed Identity.