Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions src/Aspire.Hosting/ApplicationModel/ParameterResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ namespace Aspire.Hosting.ApplicationModel;
/// </summary>
public class ParameterResource : Resource, IResourceWithoutLifetime, IManifestExpressionProvider, IValueProvider
{
private string? _value;
private bool _hasValue;
private readonly Lazy<string> _lazyValue;
private readonly Func<ParameterDefault?, string> _valueGetter;
private string? _configurationKey;

Expand All @@ -25,6 +24,7 @@ public ParameterResource(string name, Func<ParameterDefault?, string> callback,
ArgumentNullException.ThrowIfNull(callback);

_valueGetter = callback;
_lazyValue = new Lazy<string>(() => _valueGetter(Default));
Secret = secret;
}

Expand All @@ -33,18 +33,7 @@ public ParameterResource(string name, Func<ParameterDefault?, string> callback,
/// </summary>
public string Value => GetValueAsync(default).AsTask().GetAwaiter().GetResult()!;

internal string ValueInternal
{
get
{
if (!_hasValue)
{
_value = _valueGetter(Default);
_hasValue = true;
}
return _value!;
}
}
internal string ValueInternal => _lazyValue.Value;

/// <summary>
/// Represents how the default value of the parameter should be retrieved.
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Hosting/Dcp/DcpExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,6 +1097,9 @@ async Task CreateResourceExecutablesAsyncCore(IResource resource, IEnumerable<Ap

private async Task CreateExecutableAsync(AppResource er, ILogger resourceLogger, CancellationToken cancellationToken)
{
// Force async execution
await Task.Yield();

if (er.DcpResource is not Executable exe)
{
throw new InvalidOperationException($"Expected an Executable resource, but got {er.DcpResource.Kind} instead");
Expand Down Expand Up @@ -1348,6 +1351,9 @@ async Task CreateContainerAsyncCore(AppResource cr, CancellationToken cancellati

private async Task CreateContainerAsync(AppResource cr, ILogger resourceLogger, CancellationToken cancellationToken)
{
// Force async execution
await Task.Yield();

await _executorEvents.PublishAsync(new OnResourceStartingContext(cancellationToken, KnownResourceTypes.Container, cr.ModelResource, cr.DcpResource.Metadata.Name)).ConfigureAwait(false);

var dcpContainerResource = (Container)cr.DcpResource;
Expand Down
Loading