-
Notifications
You must be signed in to change notification settings - Fork 418
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use endpoint references for all allocated endpoint resolution (#2596)
* Support live references in the application model - This change removes setting manifest expressions strings in publish mode (except inputs) and pushes object references into the model directly. - This change also introduces IManifestExpressionProvider and IValueProvider as way for external code to represent manifest and values without code taking a strong dependendency on it. These are implemented on ParameterResource, IResourceWithConnectionString, EndpointReference and ConnectionStringReference in the core. - Introduce ConnectionStringReference which stores the underlying resource and an option bool (preserving the syntax of the call itself). - Added methods on EndpointReference to allow getting various parts of the URL - BicepOutputReference and BicepSecretOutputReference also implement the new interfaces. - Use endpoint references for all allocated endpoint resolution - Don't use lower level AllocatedEndpointAnnotation directly, instead use EndpointReference to represent the primary endpoint for container resources. - Pick a primary named endpoint
- Loading branch information
Showing
46 changed files
with
464 additions
and
642 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
src/Aspire.Hosting/ApplicationModel/ConnectionStringReference.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// Represents a reference to a connection string. | ||
/// </summary> | ||
public class ConnectionStringReference(IResourceWithConnectionString resource, bool optional) : IManifestExpressionProvider, IValueProvider | ||
{ | ||
/// <summary> | ||
/// The resource that the connection string is referencing. | ||
/// </summary> | ||
public IResourceWithConnectionString Resource { get; } = resource; | ||
|
||
/// <summary> | ||
/// A flag indicating whether the connection string is optional. | ||
/// </summary> | ||
public bool Optional { get; } = optional; | ||
|
||
string IManifestExpressionProvider.ValueExpression => Resource.ValueExpression; | ||
|
||
async ValueTask<string?> IValueProvider.GetValueAsync(CancellationToken cancellationToken) | ||
{ | ||
var value = await Resource.GetValueAsync(cancellationToken).ConfigureAwait(false); | ||
|
||
if (value is null && !Optional) | ||
{ | ||
throw new DistributedApplicationException($"The connection string for the resource `{Resource.Name}` is not available."); | ||
} | ||
|
||
return value; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
15 changes: 15 additions & 0 deletions
15
src/Aspire.Hosting/ApplicationModel/IManifestExpressionProvider.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// An interface that allows an object to express how it should be represented in a manifest. | ||
/// </summary> | ||
public interface IManifestExpressionProvider | ||
{ | ||
/// <summary> | ||
/// Gets the expression that represents a value in manifest. | ||
/// </summary> | ||
string ValueExpression { get; } | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
namespace Aspire.Hosting.ApplicationModel; | ||
|
||
/// <summary> | ||
/// A interface that allows the value to be provided for an environment variable. | ||
/// </summary> | ||
public interface IValueProvider | ||
{ | ||
/// <summary> | ||
/// Gets the value for use as an environment variable. | ||
/// </summary> | ||
/// <param name="cancellationToken"></param> | ||
/// <returns></returns> | ||
public ValueTask<string?> GetValueAsync(CancellationToken cancellationToken = default); | ||
} |
Oops, something went wrong.