Register a DuckDBConnection in the DI container to interact with a DuckDB database using ADO.NET.
DuckDB is an in-process analytical (OLAP) database, ideal for analytics workloads, Parquet/CSV querying, and data processing.
- A DuckDB database
Install the Aspire DuckDB client library using the following command:
dotnet add package CommunityToolkit.Aspire.DuckDB.NET.Data
In the Program.cs file of your project, call the AddDuckDBConnection extension method to register the DuckDBConnection implementation in the DI container. This method takes the connection name as a parameter:
builder.AddDuckDBConnection("analytics");Then, in your service, inject DuckDBConnection and use it to interact with the database:
public class AnalyticsService(DuckDBConnection db)
{
// ...
}