-
Notifications
You must be signed in to change notification settings - Fork 840
Expose building blocks for external service discovery implementations #6946
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
base: main
Are you sure you want to change the base?
Conversation
bf2d2f6 to
8ce3522
Compare
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 exposes building blocks for external service discovery implementations by making previously internal APIs public. The changes enable external developers to implement custom service discovery providers while maintaining consistency with internal patterns.
Key changes:
- Made
UriEndPointclass public with proper constructor and null validation - Exposed
ApplyAllowedSchemesas a public instance method onServiceDiscoveryOptions - Added
ServiceEndpoint.TryParsestatic method to provide a standard way to parse endpoint strings
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| ServiceDiscoveryOptions.cs | Changed ApplyAllowedSchemes from internal static to public instance method with XML documentation |
| ConfigurationServiceEndpointProvider.cs | Updated to use new public ApplyAllowedSchemes method and consolidated endpoint parsing logic |
| UriEndPoint.cs | Changed from internal sealed to public class with public constructor and null validation |
| ServiceEndpoint.cs | Added public TryParse method to centralize endpoint string parsing logic |
| #pragma warning disable CS8602 | ||
| if (value.IndexOf("://", StringComparison.Ordinal) < 0 && Uri.TryCreate($"fakescheme://{value}", default, out var uri)) | ||
| #pragma warning restore CS8602 |
Copilot
AI
Oct 22, 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 pragma warning disable for CS8602 is unnecessary here. The preceding check !string.IsNullOrWhiteSpace(value) on line 66 ensures that value is not null at this point, so the null-forgiving operator or null check is not needed. Remove the pragma directives.
| #pragma warning disable CS8602 | |
| if (value.IndexOf("://", StringComparison.Ordinal) < 0 && Uri.TryCreate($"fakescheme://{value}", default, out var uri)) | |
| #pragma warning restore CS8602 | |
| if (value.IndexOf("://", StringComparison.Ordinal) < 0 && Uri.TryCreate($"fakescheme://{value}", default, out var uri)) |
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.
This isn't true. The build fails without it. That's because string.IsNullOrWhiteSpace is not annotated for nullability in netstandard and netfx.
| _includeAllSchemes = serviceDiscoveryOptions.Value.AllowAllSchemes && query.IncludedSchemes.Count == 0; | ||
| _schemes = ServiceDiscoveryOptions.ApplyAllowedSchemes(query.IncludedSchemes, serviceDiscoveryOptions.Value.AllowedSchemes, serviceDiscoveryOptions.Value.AllowAllSchemes); | ||
| var allowedSchemes = serviceDiscoveryOptions.Value.ApplyAllowedSchemes(query.IncludedSchemes); | ||
| _schemes = allowedSchemes as string[] ?? allowedSchemes.ToArray(); |
Copilot
AI
Oct 22, 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.
This code performs a type check and potentially creates a new array on every instantiation. Since ApplyAllowedSchemes now returns IReadOnlyList<string> and can return different concrete types (ReadOnlyCollection<string> or List<T>.AsReadOnly()), consider storing allowedSchemes directly as IReadOnlyList<string> if _schemes field type can be changed, or call .ToArray() unconditionally to avoid the type check overhead.
| _schemes = allowedSchemes as string[] ?? allowedSchemes.ToArray(); | |
| _schemes = allowedSchemes.ToArray(); |
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 updated code employs the same optimization to avoid allocating when the runtime type is already an array. The logic has just moved.
|
@ReubenBond, can you please review this PR? |
…or nullability in netstandard/netfx
a5b1712 to
2fe85ad
Compare
|
@ReubenBond Thanks for the review and approval. |
Closes #dotnet/aspire#4224.
Microsoft Reviewers: Open in CodeFlow