Skip to content
Merged
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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the default safety mode when not specified explicitly? Is it thread safe?

I think it would be clearer to specify it explicitly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExecutionAndPublication, the one that you always want by 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
Loading