[docs] Fix Subscribe syntax bug and adopt OnConnectionStringAvailable/OnInitializeResource helpers#943
Draft
IEvangelist wants to merge 1 commit into
Draft
[docs] Fix Subscribe syntax bug and adopt OnConnectionStringAvailable/OnInitializeResource helpers#943IEvangelist wants to merge 1 commit into
IEvangelist wants to merge 1 commit into
Conversation
…/OnInitializeResource helpers Fixes #315 - app-host/eventing.mdx: add missing }); that closes the lower-level Eventing.Subscribe<AfterResourcesCreatedEvent>(...) fallback example (regression from #821 — the published code did not compile). - architecture/resource-examples.mdx: replace the standalone builder.Eventing.Subscribe<ConnectionStringAvailableEvent>(redis, ...) block with the OnConnectionStringAvailable helper chained into the fluent resource configuration. Renumber the inline step comments (4 → 4 / 5 → 5.a–5.h) so the walkthrough still tracks. - extensibility/custom-resources.mdx: rewrite the "Using inline event subscriptions" example to use OnInitializeResource, which is semantically correct for per-resource one-time init and (unlike the previous Subscribe<AfterResourcesCreatedEvent>(resource, ...) call) actually compiles. Add a sentence listing the resource-level helpers. Verified by compiling each modified code pattern against the latest Aspire 13.3 packages (aspire new aspire-empty, dotnet build) and by cross-referencing src/Aspire.Hosting/DistributedApplicationEventingExtensions.cs for helper names, generic constraints, and callback signatures. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Fixes #315
Summary
Issue #315 asked us to refresh the eventing docs to use the new resource-level helper methods (
OnInitializeResource,OnConnectionStringAvailable,OnResourceReady, etc.) and to sweep remainingEventing.Subscribe<T>usages out of the docs where a helper now applies.PR #821 already modernized the main eventing landing page and added the helper table, but:
Eventing.Subscribe<AfterResourcesCreatedEvent>(...)call is missing its closing});, so the snippet as published on https://aspire.dev/app-host/eventing/ doesn't compile.architecture/resource-examples.mdxstill usesEventing.Subscribe<ConnectionStringAvailableEvent>(redis, ...).extensibility/custom-resources.mdxusesEventing.Subscribe<AfterResourcesCreatedEvent>(resource, ...), which is a compile error today —AfterResourcesCreatedEventdoesn't implementIDistributedApplicationResourceEvent, so the resource overload ofSubscribewon't accept it.This PR fixes the three issues above and leaves all
Eventing.Subscribe<T>usages in place where no helper currently exists (e.g.AfterEndpointsAllocatedEvent,AfterResourcesCreatedEventat the AppHost level) or where it's intentional historical context (release-notes pages, low-level pattern references).Changes
src/frontend/src/content/docs/app-host/eventing.mdx— adds the missing});that closes theEventing.Subscribe<AfterResourcesCreatedEvent>(...)lower-level fallback example introduced in [docs] AppHost eventing: document OnBeforeStart, OnBeforePublish, OnAfterPublish builder extension methods #821.src/frontend/src/content/docs/architecture/resource-examples.mdx— replaces the standalonebuilder.Eventing.Subscribe<ConnectionStringAvailableEvent>(redis, ...)block withOnConnectionStringAvailable(...)chained into the resource's fluent configuration. Renumbers the inline step comments (4 → 4 / 5 → 5.a–5.h) so the prose still tracks the walkthrough's structure.src/frontend/src/content/docs/extensibility/custom-resources.mdx— rewrites the "Using inline event subscriptions" example to useOnInitializeResource((resource, @event, ct) => ...), which actually compiles and is semantically correct for the section's intent (per-resource one-time initialization). Adds a sentence listing the resource-level helpers so readers can see the full set.Evidence the bugs are live
Captured from https://aspire.dev on the day of this PR (the published HTML for the same code blocks):
https://aspire.dev/app-host/eventing/— missing});:https://aspire.dev/architecture/resource-examples/— uses old API:https://aspire.dev/extensibility/custom-resources/— uses the resource overload with an event type that doesn't satisfy the generic constraint:How I verified
API surface check — read
src/Aspire.Hosting/DistributedApplicationEventingExtensions.csandsrc/Aspire.Hosting/Eventing/IDistributedApplicationEventing.csinmicrosoft/aspireto enumerate the AppHost-level helpers (OnBeforeStart,OnBeforePublish,OnAfterPublish) and resource-level helpers (OnBeforeResourceStarted,OnResourceStopped,OnConnectionStringAvailable,OnInitializeResource,OnResourceEndpointsAllocated,OnResourceReady), and to confirm the generic constraints (T : IDistributedApplicationEventvsT : IDistributedApplicationResourceEventvsT : IResourceWithConnectionString).Compile-check — scaffolded an empty AppHost with
aspire new aspire-empty --language csharpand copied each of the modified code patterns into it (Subscribe<AfterResourcesCreatedEvent>(...)with the closing});,OnBeforeStart/OnBeforePublish/OnAfterPublishon the builder,OnConnectionStringAvailable((resource, @event, ct) => ...)on aRedisResourcechain,OnInitializeResource((resource, @event, ct) => ...)on a resource builder).dotnet buildsucceeds with no errors or warnings.Live regression confirmation — fetched the three pages on
https://aspire.devdirectly and observed the broken/outdated code blocks above.Notes
architecture/resource-hierarchies.mdxstill usesEventing.Subscribe<AfterEndpointsAllocatedEvent>(...)— left as-is, because no helper exists forAfterEndpointsAllocatedEvent.architecture/resource-api-patterns.mdxreferencesSubscribe<T>deliberately as the underlying pattern — left as-is.whats-new/*.mdxrelease notes also referenceEventing.Subscribe<T>— left as-is; these are historical and intentionally describe the API of that release.Subscribe<ResourceStoppedEvent>(cache, ...)example near the bottom ofapp-host/eventing.mdx(line ~416) could be modernized tocache.OnResourceStopped(...). I left it alone to keep this PR scoped to the issue's reported defects; happy to fold it in if reviewers prefer.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com