Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sample showing how to use the support in Aspire.Hosting for database containers #61

Merged
merged 17 commits into from
Dec 20, 2023

Conversation

DamianEdwards
Copy link
Member

Note: Builds on #55

This sample demonstrates how to use the built-in support for database containers in .NET Aspire when not using an ORM like Entity Framework Core, that can handle complicated database initialization logic for you. In this sample, the underlying features of the database container images are utilized to modify the database upon container start, e.g. changing the name of the default database, creating tables and inserting seed data via a .sql script, etc. The API app that depends on the database uses Dapper to make its queries.

The PostgreSQL and MySql containers both support modifying the database name via an environment variable and initializing the database via *.sql scripts in a bound directory. The MS SQL Server container does not support this so instead I adapted their example for customizing the database via a custom container entry point.

Fixes #60

NuGet.config Outdated Show resolved Hide resolved
build.cmd Outdated Show resolved Hide resolved
build.sh Outdated Show resolved Hide resolved
Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for writing up this sample.

@DamianEdwards
Copy link
Member Author

@bgrainger would love your thoughts on this too, esp. the MySql init script as I've never used MySql before and relied on CoPilot and StackOverflow to build 😄

@DamianEdwards DamianEdwards merged commit 04c1f43 into main Dec 20, 2023
3 checks passed
@DamianEdwards DamianEdwards deleted the damianedwards/db-containers branch December 20, 2023 17:57
meneasysoft pushed a commit to meneasysoft/aspire-samples that referenced this pull request Jul 25, 2024
…ase containers (dotnet#61)

* Updating samples for preview.2

* Skip sign check on workload install for now

* Update NuGet.config

* Update to latest preview.2 build

* Update to latest preview.2 build

* Fix node sample

* Update the version of preview2 to the latest

* Updated the dapr sample and instructions

* Update Dapr README to call out dapr init (dotnet#66)

* Update to latest package versions

* WIP

* Added DatabaseContainers sample

Fixes dotnet#60

* Tweaks

* Inject connection from DI instead of DataSource

* Update samples/DatabaseContainers/README.md

Co-authored-by: Bradley Grainger <[email protected]>

* Prepare for release

---------

Co-authored-by: David Fowler <[email protected]>
Co-authored-by: Balamurugan Chirtsabesan <[email protected]>
Co-authored-by: Bradley Grainger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add samples showing how to use the support in Aspire.Hosting for database containers
5 participants