.NET Aspire Database Containers sample

This sample demonstrates working with database containers in a .NET Aspire app, using the features of the underlying container image to modify the default database created during container startup. This is especially helpful when not using an ORM like Entity Framework Core that can run migrations on application startup (e.g., as in the Aspire Shop sample) and handle cases when the database configured in the AppHost is not yet created.

Screenshot of the Swagger UI for the API service that returns data from the configured database containers

The app uses the following database container types:

The app consists of an API service:

  • ContainerDatabases.ApiService: This is an HTTP API that returns data from each of the configured databases.

Pre-requisites

Running the app

If using Visual Studio, open the solution file DatabaseContainers.sln and launch/debug the DatabaseContainers.AppHost project.

If using the .NET CLI, run dotnet run from the DatabaseContainers.AppHost directory.

From the Aspire dashboard, click on the endpoint URL for the ContainerDatabases.ApiService project to launch the Swagger UI for the APIs. You can use the UI to call the APIs and see the results.