Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
All reported issues were addressed across 138 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
devhl-labs
deleted the
devhl/23595-add-support-for-IHostApplicationBuilder
branch
September 16, 2026 12:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
IHostApplicationBuildersupport to the C# generichost generatorProblem
The generichost library generates DI wiring extension methods only for
IHostBuilder(viaConfigureApion the host builder) andIServiceCollection(viaAddApi). Both are built around the legacy generic-host model that starts fromHost.CreateDefaultBuilder(args).Modern .NET has moved on. Since .NET 8, the recommended and template-default way to bootstrap an app is the streamlined
Host.CreateApplicationBuilder()/WebApplicationBuildermodel, which exposes anIHostApplicationBuilder. Microsoft's own guidance describes the olderIHostBuilderapproach as a legacy pattern kept for compatibility, whileIHostApplicationBuilderis "recommended for new projects and is the default in current .NET templates."Consumers on that modern hosting model had no first-class way to register the generated client. They were forced to drop down to
builder.Services.AddApi(...), or hand-roll their ownIHostApplicationBuilderextension method — which defeats the purpose of a generated SDK. This was raised in #23595.Solution
The generator now emits an
IHostApplicationBuilderExtensionsclass alongside the existing extensions, providing aConfigureApioverload that hangs directly offIHostApplicationBuilder:The new method mirrors the existing surface exactly: it constructs a
HostConfiguration, invokes the caller's configuration delegate, and forwards to the sameIServiceCollectionExtensions.AddApicore registration. As a result, every existing extensibility hook (OnHostConfigurationCreated,OnAddApiHttpClientBuilder,OnServicesAdded) fires identically no matter which entry point a consumer uses — there's a single registration path, just three different front doors.The signature intentionally follows idiomatic .NET DI conventions and stays consistent with the sibling
AddApi(this IServiceCollection, Action<HostConfiguration>)overload: a single configuration delegate, with the builder returned for fluent chaining. Anyone needing the rawIServiceCollectionstill has it directly asbuilder.Services.Because
Host.CreateApplicationBuilder()and theIHostApplicationBuilderinterface only exist on .NET 8+, the generated class is gated behind thenet80OrLaterflag so older target frameworks (net6/net7) are unaffected. The README usage sample follows the same gate, showing the modernHost.CreateApplicationBuilder()pattern for net8+ projects and the existingIHostBuilderpattern otherwise — one canonical example per generated project, always matching the target framework.Closes #23595.
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Adds
IHostApplicationBuildersupport to the C# generichost generator so .NET 8+ apps usingHost.CreateApplicationBuilder()can register the generated client via a newConfigureApiextension instead of falling back tobuilder.Services.AddApi(...). The extension forwards to the existingIServiceCollectionExtensions.AddApiregistration path, keeping extensibility hooks identical regardless of entry point, and is only emitted fornet80OrLatertargets. Closes #23595.New Features
IHostApplicationBuilderExtensionsclass with aConfigureApioverload, gated behindnet80OrLaterso older target frameworks are unaffected.Host.CreateApplicationBuilder()for net8+ targets and keep theIHostBuilderpattern for older ones.Written for commit 6401e56. Summary will update on new commits.