-
Notifications
You must be signed in to change notification settings - Fork 682
Allow YARP to be configured in a programmatic way #9766
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
Conversation
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 introduces programmatic configuration of YARP in the AppHost by leveraging an existing YARP configuration model and adding custom JSON serialization support.
- New test methods to verify YARP configuration via config files and programmatically.
- Refactored YARP service extensions and resource classes to support programmatic configuration through a dedicated builder interface and implementation.
- Updated the project file to add the required package reference and test visibility.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
tests/Aspire.Hosting.Yarp.Tests/YarpFunctionalTests.cs | Added tests to verify both config file and programmatic configuration. |
src/Aspire.Hosting.Yarp/YarpServiceExtensions.cs | Updated extensions to use the new configuration builder API. |
src/Aspire.Hosting.Yarp/YarpResource.cs | Replaced the config file property with a configuration builder. |
src/Aspire.Hosting.Yarp/YarpConfigurationBuilder.cs | New builder implementation for programmatic configuration. |
src/Aspire.Hosting.Yarp/IYarpConfigurationBuilder.cs | Introduced the builder interface. |
src/Aspire.Hosting.Yarp/Aspire.Hosting.Yarp.csproj | Updated to include the YARP package and expose internals to tests. |
spelling.dic | Added a duplicate entry for "Yarp". |
Comments suppressed due to low confidence (1)
tests/Aspire.Hosting.Yarp.Tests/YarpFunctionalTests.cs:78
- The health check endpoint '/heath' may be a misspelling; consider verifying if '/health' is the intended path.
.WithHttpHealthCheck("/heath", 404); // TODO we don't have real health check path yet
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Not necessarily to merge with this PR but we can we try out a higher level API that composes on top of this lower level API. I just want to make sure there are no gotchas if we want to do something like: builder.AddYarp(...)
.FowardsTo(backend, "/api/{**catch-all}"); |
Sure thing, have a look at my current proto: https://github.com/benjaminpetit/aspire/blob/8b4df33c99dbe76d63489fc20bef6840c352901f/tests/Aspire.Hosting.Yarp.Tests/YarpFunctionalTests.cs#L83 (or just this branch in general: https://github.com/benjaminpetit/aspire/tree/8b4df33c99dbe76d63489fc20bef6840c352901f) Right now I manage to do things like this: yarp.WithReference(
proxiedResource: backend.GetEndpoint("http"),
routeMatch: new RouteMatch { Path = "/aspnetapp/{**catch-all}" },
transforms: transforms => transforms.WithTransformPathRemovePrefix("/aspnetapp")
); I am also experimenting with having extensions directly on the proxied resource, instead of on the YARP instance. |
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 only test is quarantined?
Description
This PR enables developers to configure a YARP instance directly in the AppHost using code. It adopts the same configuration model as standard YARP, making it easier for developers already familiar with YARP to transition to this approach.
Key Details
Usage example
Checklist
<remarks />
and<code />
elements on your triple slash comments?doc-idea
templatebreaking-change
templatediagnostic
template