Aspire 9.4 , between many improvements detailed at https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9.4 , adds events bound directly to resource.
So the code for SqlExtensionsAspire become more simple . I have the db resource and I want to execute Sql when it is ready . From 9.3 code
builder.Eventing.Subscribe<ResourceReadyEvent>(async (ev, ct) => { if (ev.Resource is not SqlServerDatabaseResource dbRes) return; if (db.Resource != dbRes) return; var cn = await dbRes.ConnectionStringExpression.GetValueAsync(ct); if (cn == null) return; // Set up logging for script execution var log = ev.Services.GetService(typeof(ResourceLoggerService)) as ResourceLoggerService;
to 9.4 code
// Subscribe to the resource ready event to execute scripts when database is available db.OnResourceReady(async (dbRes, ev, ct) => { // Get the database connection string var cn = await dbRes.ConnectionStringExpression.GetValueAsync(ct); if (cn == null) return; // Set up logging for script execution var log = ev.Services.GetService(typeof(ResourceLoggerService)) as ResourceLoggerService;