Skip to content

Commit 8b77a29

Browse files
committed
Fix build breaks and nullability in public APIs
1 parent 1740335 commit 8b77a29

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

src/Aspire.Hosting/ApplicationModel/ResourceExtensions.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,15 @@ public static bool TryGetUrls(this IResource resource, [NotNullWhen(true)] out I
673673
/// </summary>
674674
/// <param name="resource">The <see cref="IResourceWithEndpoints"/> which contains <see cref="EndpointAnnotation"/> annotations.</param>
675675
/// <returns>An enumeration of <see cref="EndpointReference"/> based on the <see cref="EndpointAnnotation"/> annotations from the resources' <see cref="IResource.Annotations"/> collection.</returns>
676-
public static IEnumerable<EndpointReference> GetEndpoints(this IResourceWithEndpoints resource) => resource.GetEndpoints(null);
676+
public static IEnumerable<EndpointReference> GetEndpoints(this IResourceWithEndpoints resource)
677+
{
678+
if (TryGetAnnotationsOfType<EndpointAnnotation>(resource, out var endpoints))
679+
{
680+
return endpoints.Select(e => new EndpointReference(resource, e));
681+
}
682+
683+
return [];
684+
}
677685

678686

679687
/// <summary>
@@ -698,7 +706,7 @@ public static IEnumerable<EndpointReference> GetEndpoints(this IResourceWithEndp
698706
/// <param name="resource">The <see cref="IResourceWithEndpoints"/> which contains <see cref="EndpointAnnotation"/> annotations.</param>
699707
/// <param name="endpointName">The name of the endpoint.</param>
700708
/// <returns>An <see cref="EndpointReference"/>object providing resolvable reference for the specified endpoint.</returns>
701-
public static EndpointReference GetEndpoint(this IResourceWithEndpoints resource, string endpointName) => resource.GetEndpoint(endpointName, null);
709+
public static EndpointReference GetEndpoint(this IResourceWithEndpoints resource, string endpointName) => resource.GetEndpoint(endpointName);
702710

703711
/// <summary>
704712
/// Gets an endpoint reference for the specified endpoint name.
@@ -719,7 +727,6 @@ public static EndpointReference GetEndpoint(this IResourceWithEndpoints resource
719727
}
720728
else
721729
{
722-
contextNetworkID ??= endpoint.DefaultNetworkID;
723730
return new EndpointReference(resource, endpoint, contextNetworkID);
724731
}
725732

src/Aspire.Hosting/ResourceBuilderExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public static IResourceBuilder<T> WithEndpoint<T>(this IResourceBuilder<T> build
807807
}
808808

809809
/// <summary>
810-
/// Exposes an endpoint on a resource. A reference to this endpoint can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier?)"/>.
810+
/// Exposes an endpoint on a resource. A reference to this endpoint can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier)"/>.
811811
/// The endpoint name will be the scheme name if not specified.
812812
/// </summary>
813813
/// <typeparam name="T">The resource type.</typeparam>
@@ -863,7 +863,7 @@ public static IResourceBuilder<T> WithEndpoint<T>(this IResourceBuilder<T> build
863863
}
864864

865865
/// <summary>
866-
/// Exposes an endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier?)"/>.
866+
/// Exposes an endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier)"/>.
867867
/// The endpoint name will be the scheme name if not specified.
868868
/// </summary>
869869
/// <typeparam name="T">The resource type.</typeparam>
@@ -883,7 +883,7 @@ public static IResourceBuilder<T> WithEndpoint<T>(this IResourceBuilder<T> build
883883
}
884884

885885
/// <summary>
886-
/// Exposes an HTTP endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier?)"/>.
886+
/// Exposes an HTTP endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier)"/>.
887887
/// The endpoint name will be "http" if not specified.
888888
/// </summary>
889889
/// <typeparam name="T">The resource type.</typeparam>
@@ -903,7 +903,7 @@ public static IResourceBuilder<T> WithHttpEndpoint<T>(this IResourceBuilder<T> b
903903
}
904904

905905
/// <summary>
906-
/// Exposes an HTTPS endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier?)"/>.
906+
/// Exposes an HTTPS endpoint on a resource. This endpoint reference can be retrieved using <see cref="ResourceBuilderExtensions.GetEndpoint{T}(IResourceBuilder{T}, string, NetworkIdentifier)"/>.
907907
/// The endpoint name will be "https" if not specified.
908908
/// </summary>
909909
/// <typeparam name="T">The resource type.</typeparam>
@@ -957,7 +957,7 @@ public static IResourceBuilder<T> WithExternalHttpEndpoints<T>(this IResourceBui
957957
/// <param name="name">The name of the endpoint.</param>
958958
/// <param name="contextNetworkID">The network context in which to resolve the endpoint. If null, localhost (loopback) network context will be used.</param>
959959
/// <returns>An <see cref="EndpointReference"/> that can be used to resolve the address of the endpoint after resource allocation has occurred.</returns>
960-
public static EndpointReference GetEndpoint<T>(this IResourceBuilder<T> builder, [EndpointName] string name, NetworkIdentifier? contextNetworkID = null) where T : IResourceWithEndpoints
960+
public static EndpointReference GetEndpoint<T>(this IResourceBuilder<T> builder, [EndpointName] string name, NetworkIdentifier contextNetworkID) where T : IResourceWithEndpoints
961961
{
962962
ArgumentNullException.ThrowIfNull(builder);
963963

@@ -976,7 +976,7 @@ public static EndpointReference GetEndpoint<T>(this IResourceBuilder<T> builder,
976976
{
977977
ArgumentNullException.ThrowIfNull(builder);
978978

979-
return builder.Resource.GetEndpoint(name, null);
979+
return builder.Resource.GetEndpoint(name);
980980
}
981981

982982
/// <summary>

tests/Aspire.Hosting.Tests/ExecutableResourceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task AddExecutableWithArgs()
3636
context.Args.Add("arg2");
3737
context.Args.Add(exe1.GetEndpoint("ep"));
3838
context.Args.Add(testResource2);
39-
context.Args.Add(((IResourceWithEndpoints)context.Resource).GetEndpoint("ep", null));
39+
context.Args.Add(((IResourceWithEndpoints)context.Resource).GetEndpoint("ep"));
4040
});
4141

4242
using var app = appBuilder.Build();

tests/Aspire.Hosting.Tests/ProjectResourceTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public async Task AddProjectWithArgs()
599599
{
600600
context.Args.Add("arg1");
601601
context.Args.Add(c1.GetEndpoint("ep"));
602-
context.Args.Add(((IResourceWithEndpoints)context.Resource).GetEndpoint("ep", null));
602+
context.Args.Add(((IResourceWithEndpoints)context.Resource).GetEndpoint("ep"));
603603
});
604604

605605
using var app = appBuilder.Build();
@@ -645,8 +645,8 @@ public async Task AddProjectWithWildcardUrlInLaunchSettings(bool isProxied)
645645

646646
var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(resource, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout();
647647

648-
var http = resource.GetEndpoint("http", null);
649-
var https = resource.GetEndpoint("https", null);
648+
var http = resource.GetEndpoint("http");
649+
var https = resource.GetEndpoint("https");
650650

651651
if (isProxied)
652652
{

0 commit comments

Comments
 (0)