What are the recommendations to initialize dependencies #1809
Answered
by
davidfowl
paulomorgado
asked this question in
Q&A
-
In my Aspire project I have service dependencies like databases, queues, etc. What are the recommended ways to initialize/seed these dependencies before the services start? |
Beta Was this translation helpful? Give feedback.
Answered by
davidfowl
Aug 6, 2025
Replies: 1 comment 1 reply
-
Hi @paulomorgado, var db = builder.AddPostgres("pg")
.WithImage("postgres:16");
var init = builder.AddProject<Projects.DbInitializer>("db-init")
.WithReference(db)
.WaitFor(db); // waits until DB container is ready
builder.AddProject<Projects.MyService>("my-service")
.WithReference(db)
.WaitFor(init); // starts only after init finishes This way, dependent services only start once the resources are ready in healthy state. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can also handle OnResourceReady and put it in there if this is for development only.