aspire
aspire copied to clipboard
Preserve the type of application builder in chained extension methods
This is a slight improvement to the usability of extensions in the ServiceDefaults project template. Previously, you couldn't chain WebApplication.CreateBuilder and the ServiceDefaults extensions.
For example, this code won't compile:
var builder = WebApplication.CreateBuilder(args)
.AddServiceDefaults();
var app = builder.Build();
// ^^^^^
// CS1061: 'IHostApplicationBuilder' does not contain a definition for 'Build' and no accessible extension method 'Build' accepting a first argument of type 'IHostApplicationBuilder' could be found
After this change, compilation will succeed.
Microsoft Reviewers: Open in CodeFlow
@mitchdenny @DamianEdwards @davidfowl - thoughts here?
If we take this change, we need to update ServiceDefaults everywhere - playground apps, all the templates, etc.
I don't have a problem with this change, but the PR will need to include the fixes to playground apps etc as @eerhardt has identified.
I would defer to folks who have had to deal with the reality of project template changes over time and what issues that can introduce though.
This seems like something we should consider for 9.0
@sliekens did you want to add the playground app updates here too?
Yeah I realized after creating the PR that the ServiceDefaults template was not the only place to make changes, though I'm not sure how many other projects would need to be changed.
If you look under /playground you'll see that we generally share a single service defaults project there.
@mitchdenny I'm noticing other kinds of drift between the different copies of the Extensions.cs, is it okay if I re-align them while I'm making this change?
.e.g. #4096 removed broken Prometheus examples from the templates but they are still present in the playground apps.
@DamianEdwards thanks for the review, I removed the unused directives and I updated every usage I could find of IHostApplicationBuilder in the playground.