Register a SqliteConnection in the DI container to interact with a SQLite database using ADO.NET.
- A SQLite database
Install the Aspire EF Core Sqlite library using the following command:
dotnet add package CommunityToolkit.Aspire.Microsoft.Data.Sqlite
In the Program.cs file of your project, call the AddSqliteConnection extension method to register the SqliteConnection implementation in the DI container. This method takes the connection name as a parameter:
builder.AddSqliteConnection("sqlite");Then, in your service, inject SqliteConnection and use it to interact with the database:
public class MyService(SqliteConnection context)
{
// ...
}