-
Notifications
You must be signed in to change notification settings - Fork 707
Add async PipelineStepFactoryContext and WithPipelineStepFactory extension methods #12165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add async PipelineStepFactoryContext and WithPipelineStepFactory extension methods #12165
Conversation
…e properties Co-authored-by: davidfowl <[email protected]>
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12165Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12165" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the PipelineStepAnnotation by introducing a PipelineStepFactoryContext that provides factory functions with access to both the pipeline context and the specific resource. This enables more sophisticated pipeline step creation based on resource properties and the broader application model.
- Introduced
PipelineStepFactoryContextclass withPipelineContextandIResourceproperties - Updated
PipelineStepAnnotationconstructors and factory signature to accept the new context - Modified pipeline execution to create and pass context instances to factories
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| PipelineStepFactoryContext.cs | New context class providing pipeline context and resource access to factory functions |
| PipelineStepAnnotation.cs | Updated factory signature and constructors to use the new context parameter |
| DistributedApplicationPipeline.cs | Modified to create and pass factory context when collecting steps from annotations |
| AzureEnvironmentResource.cs | Updated usage to match new factory signature with context parameter |
| DistributedApplicationPipelineTests.cs | Updated all test cases to use new factory signature and added context verification test |
| public class PipelineStepFactoryContext | ||
| { | ||
| /// <summary> | ||
| /// Gets the pipeline context that has the model and other properties. |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary description lacks detail about what the pipeline context contains and how it should be used. Consider expanding to mention specific capabilities like accessing the application model, services, logger, etc.
| /// Gets the pipeline context that has the model and other properties. | |
| /// Gets the <see cref="PipelineContext"/> that provides access to the application model, registered services, logging facilities, and other contextual information required for creating pipeline steps. |
| public required PipelineContext PipelineContext { get; init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the resource that this factory is associated with. |
Copilot
AI
Oct 18, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary should clarify that this is the specific resource for which the factory is creating pipeline steps, and mention how this enables resource-specific step creation.
| /// Gets the resource that this factory is associated with. | |
| /// Gets the specific resource for which the factory is creating pipeline steps. | |
| /// This enables resource-specific step creation within the pipeline. |
|
@copilot This factory needs to be async to support walking parts of the the resource graph to create steps. |
… graph Co-authored-by: davidfowl <[email protected]>
Made the factory async to support walking the resource graph. The factory signature is now |
|
@copilot add an extension method WithPipelineStep that adds the annotation with a sync an async overload and make it experimental |
Co-authored-by: davidfowl <[email protected]>
Added |
|
@copilot Update the code to use WithPipelineStep |
|
@copilot Look at code using new PipelineStepAnnotation and make it use WithPipelineStep if possible |
Co-authored-by: davidfowl <[email protected]>
Updated all code to use |
All code that can use |
|
@copilot Rename WithPipelineStep to WithPipelineStepFactory |
Co-authored-by: davidfowl <[email protected]>
Renamed |
|
@copilot PipelineStep.DependsOnSteps Should be init properties. You should never be able to set these to null, they can be empty or non empty. |
Co-authored-by: davidfowl <[email protected]>
Changed |
Summary
This PR implements a follow-up enhancement to
PipelineStepAnnotationthat enables factory functions to access both the pipeline context and the specific resource when creating pipeline steps asynchronously. It also adds convenient extension methods for adding pipeline steps to resources.Changes
New
PipelineStepFactoryContextClassIntroduced a new context class that provides:
PipelineContext- Access to the application model, services, logger, and other pipeline-wide propertiesIResource- Reference to the specific resource the factory is creating steps forThis enables factories to make decisions based on:
Updated
PipelineStepAnnotation- Now Async with Sync OverloadsChanged the factory signature from:
To support both sync and async patterns with 4 constructor overloads:
The synchronous constructor overloads internally wrap delegates to make them async-compatible, eliminating the need for users to call
Task.FromResultin their code. TheCreateStepsAsync()method returns a Task to support asynchronous step creation, enabling factories to walk parts of the resource graph asynchronously when creating steps.New
WithPipelineStepFactoryExtension MethodsAdded convenient extension methods to simplify adding pipeline steps to resources:
WithPipelineStepFactory(Func<PipelineStepFactoryContext, PipelineStep>)- Synchronous single stepWithPipelineStepFactory(Func<PipelineStepFactoryContext, Task<PipelineStep>>)- Asynchronous single stepWithPipelineStepFactory(Func<PipelineStepFactoryContext, IEnumerable<PipelineStep>>)- Synchronous multiple stepsWithPipelineStepFactory(Func<PipelineStepFactoryContext, Task<IEnumerable<PipelineStep>>>)- Asynchronous multiple stepsAll extension methods are marked as experimental with
ASPIREPIPELINES001. All existing code has been updated to use these extension methods for better discoverability and cleaner syntax.Updated Pipeline Execution
Modified
DistributedApplicationPipeline.CollectStepsFromAnnotationsAsync()to be async and create and pass aPipelineStepFactoryContextinstance for each resource when collecting steps from annotations.Updated PipelineStep Properties
Changed
DependsOnStepsandRequiredByStepsto beinitproperties that can be initialized but never set to null. They default to empty collections and can be set during object initialization, but cannot be reassigned after initialization.Example Usage
Verification
WithPipelineStepFactoryextension methodsTask.FromResultrequired in user codeDependsOnStepsandRequiredByStepsare init properties that cannot be nullBreaking Change Note
This is a breaking change to the experimental
PipelineStepAnnotationAPI (marked withASPIREPIPELINES001). All existing usages have been updated in this PR.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.