Skip to content

Commit 3661f04

Browse files
github-actions[bot]Copilotdavidfowlmitchdennyeerhardt
authored
[release/9.4] Mark ParameterResource.Value as obsolete in favor of GetValueAsync and direct usage (#10701)
* Initial plan * Mark ParameterResource.Value as obsolete and update internal usage Co-authored-by: davidfowl <[email protected]> * Remove defaultValue parameter setting and use deferred resolution for ParameterResource values Co-authored-by: davidfowl <[email protected]> * Store ParameterResource in HelmExpressionWithValue and defer default value resolution Co-authored-by: davidfowl <[email protected]> * Make MapParameter and callees async and use GetValueAsync Co-authored-by: davidfowl <[email protected]> * Remove uses of parameter.Value in AzurePublishingContext.cs Co-authored-by: davidfowl <[email protected]> * Use BicepIdentifier instead of Value.Compile() for ParameterResource scope resolution Co-authored-by: davidfowl <[email protected]> * Revert tuple destructuring changes and correctly use BicepIdentifier instead of obsolete Value property Co-authored-by: davidfowl <[email protected]> * Revert AzurePublishingContext.cs to original synchronous Visit call Co-authored-by: davidfowl <[email protected]> * Remove pragma warning disable for obsolete ParameterResource.Value usage in AzurePublishingContext Co-authored-by: davidfowl <[email protected]> * Make MapParameter async and use p.GetValueAsync instead of obsolete property Co-authored-by: davidfowl <[email protected]> * Suppress obsolete warnings for ParameterResource.Value in test files Co-authored-by: davidfowl <[email protected]> * Move pragma. * Revert changes to Azure, Docker and K8s publisher. Instead suppress the obsoletion. --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: davidfowl <[email protected]> Co-authored-by: Mitch Denny <[email protected]> Co-authored-by: Eric Erhardt <[email protected]>
1 parent 979bc9d commit 3661f04

File tree

18 files changed

+78
-0
lines changed

18 files changed

+78
-0
lines changed

src/Aspire.Hosting.Azure/AzurePublishingContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,9 @@ private void MapParameter(object? candidate)
372372

373373
if (!p.Secret && p.Default is not null)
374374
{
375+
#pragma warning disable CS0618 // Type or member is obsolete
375376
pp.Value = p.Value;
377+
#pragma warning restore CS0618 // Type or member is obsolete
376378
}
377379

378380
ParameterLookup[p] = pp;

src/Aspire.Hosting.Docker/DockerComposeServiceExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,14 @@ public static string AsEnvironmentPlaceholder(this ParameterResource parameter,
9595

9696
// Treat secrets as environment variable placeholders as for now
9797
// this doesn't handle generation of parameter values with defaults
98+
#pragma warning disable CS0618 // Type or member is obsolete
9899
return dockerComposeService.Parent.AddEnvironmentVariable(
99100
env,
100101
description: $"Parameter {parameter.Name}",
101102
defaultValue: parameter.Secret || parameter.Default is null ? null : parameter.Value,
102103
source: parameter
103104
);
105+
#pragma warning restore CS0618 // Type or member is obsolete
104106
}
105107

106108
internal static string AsContainerImagePlaceholder(this DockerComposeServiceResource dockerComposeService)

src/Aspire.Hosting.Kubernetes/KubernetesServiceResourceExtensions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ private static HelmExpressionWithValue AllocateParameter(ParameterResource param
122122
formattedName.ToHelmSecretExpression(resource.Name) :
123123
formattedName.ToHelmConfigExpression(resource.Name);
124124

125+
#pragma warning disable CS0618 // Type or member is obsolete
125126
var value = parameter.Default is null || parameter.Secret ? null : parameter.Value;
127+
#pragma warning restore CS0618 // Type or member is obsolete
126128
return new(expression, value);
127129
}
128130

src/Aspire.Hosting/ApplicationModel/ParameterResource.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ public ParameterResource(string name, Func<ParameterDefault?, string> callback,
3131
/// <summary>
3232
/// Gets the value of the parameter.
3333
/// </summary>
34+
/// <remarks>
35+
/// This property is obsolete. Use <see cref="GetValueAsync(CancellationToken)"/> for async access or pass the <see cref="ParameterResource"/> directly to methods that accept it (e.g., environment variables).
36+
/// </remarks>
37+
[Obsolete("Use GetValueAsync for async access or pass the ParameterResource directly to methods that accept it (e.g., environment variables).")]
3438
public string Value => GetValueAsync(default).AsTask().GetAwaiter().GetResult()!;
3539

3640
internal string ValueInternal => _lazyValue.Value;

tests/Aspire.Hosting.Azure.Tests/AzureRedisExtensionsTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ public async Task AddAzureRedisRunAsContainerProducesCorrectConnectionString()
103103
Assert.True(redis.Resource.IsContainer(), "The resource should now be a container resource.");
104104

105105
Assert.NotNull(redisResource?.PasswordParameter);
106+
#pragma warning disable CS0618 // Type or member is obsolete
106107
Assert.Equal($"localhost:12455,password={redisResource.PasswordParameter.Value}", await redis.Resource.ConnectionStringExpression.GetValueAsync(CancellationToken.None));
108+
#pragma warning restore CS0618 // Type or member is obsolete
107109
}
108110

109111
[Fact]
@@ -195,7 +197,9 @@ public async Task PublishAsRedisPublishesRedisAsAzureRedisInfrastructure()
195197
Assert.True(redis.Resource.IsContainer());
196198
Assert.NotNull(redis.Resource.PasswordParameter);
197199

200+
#pragma warning disable CS0618 // Type or member is obsolete
198201
Assert.Equal($"localhost:12455,password={redis.Resource.PasswordParameter.Value}", await redis.Resource.GetConnectionStringAsync());
202+
#pragma warning restore CS0618 // Type or member is obsolete
199203

200204
var manifest = await AzureManifestUtils.GetManifestWithBicep(redis.Resource);
201205

tests/Aspire.Hosting.Milvus.Tests/MilvusFunctionalTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
7777
{
7878
using var builder1 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper);
7979
var milvus1 = builder1.AddMilvus("milvus1");
80+
#pragma warning disable CS0618 // Type or member is obsolete
8081
var password = milvus1.Resource.ApiKeyParameter.Value;
82+
#pragma warning restore CS0618 // Type or member is obsolete
8183

8284
var db1 = milvus1.AddDatabase("milvusdb1", dbname);
8385

tests/Aspire.Hosting.MongoDB.Tests/AddMongoDBTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,13 @@ public async Task MongoDBCreatesConnectionString()
8888
Assert.NotNull(connectionStringResource);
8989
var connectionString = await connectionStringResource.GetConnectionStringAsync();
9090

91+
#pragma warning disable CS0618 // Type or member is obsolete
9192
Assert.Equal($"mongodb://admin:{dbResource.Parent.PasswordParameter?.Value}@localhost:27017?authSource=admin&authMechanism=SCRAM-SHA-256", await serverResource.GetConnectionStringAsync());
93+
#pragma warning restore CS0618 // Type or member is obsolete
9294
Assert.Equal("mongodb://admin:{mongodb-password.value}@{mongodb.bindings.tcp.host}:{mongodb.bindings.tcp.port}?authSource=admin&authMechanism=SCRAM-SHA-256", serverResource.ConnectionStringExpression.ValueExpression);
95+
#pragma warning disable CS0618 // Type or member is obsolete
9396
Assert.Equal($"mongodb://admin:{dbResource.Parent.PasswordParameter?.Value}@localhost:27017/mydatabase?authSource=admin&authMechanism=SCRAM-SHA-256", connectionString);
97+
#pragma warning restore CS0618 // Type or member is obsolete
9498
Assert.Equal("mongodb://admin:{mongodb-password.value}@{mongodb.bindings.tcp.host}:{mongodb.bindings.tcp.port}/mydatabase?authSource=admin&authMechanism=SCRAM-SHA-256", connectionStringResource.ConnectionStringExpression.ValueExpression);
9599
}
96100

tests/Aspire.Hosting.MongoDB.Tests/MongoDbFunctionalTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
118118
{
119119
using var builder1 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper);
120120
var mongodb1 = builder1.AddMongoDB("mongodb");
121+
#pragma warning disable CS0618 // Type or member is obsolete
121122
var password = mongodb1.Resource.PasswordParameter!.Value;
123+
#pragma warning restore CS0618 // Type or member is obsolete
122124
var db1 = mongodb1.AddDatabase(dbName);
123125

124126
if (useVolume)

tests/Aspire.Hosting.MySql.Tests/MySqlFunctionalTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ public async Task WithDataShouldPersistStateBetweenUsages(bool useVolume)
130130
using var builder1 = TestDistributedApplicationBuilder.CreateWithTestContainerRegistry(testOutputHelper);
131131

132132
var mysql1 = builder1.AddMySql("mysql").WithEnvironment("MYSQL_DATABASE", mySqlDbName);
133+
#pragma warning disable CS0618 // Type or member is obsolete
133134
var password = mysql1.Resource.PasswordParameter.Value;
135+
#pragma warning restore CS0618 // Type or member is obsolete
134136

135137
var db1 = mysql1.AddDatabase(mySqlDbName);
136138

tests/Aspire.Hosting.Nats.Tests/AddNatsTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public async Task AddNatsSetsDefaultUserNameAndPasswordAndIncludesThemInConnecti
4040
.WithEndpoint("tcp", e => e.AllocatedEndpoint = new AllocatedEndpoint(e, "localhost", 4222));
4141

4242
Assert.NotNull(nats.Resource.PasswordParameter);
43+
#pragma warning disable CS0618 // Type or member is obsolete
4344
Assert.False(string.IsNullOrEmpty(nats.Resource.PasswordParameter!.Value));
45+
#pragma warning restore CS0618 // Type or member is obsolete
4446

4547
using var app = appBuilder.Build();
4648

@@ -51,7 +53,9 @@ public async Task AddNatsSetsDefaultUserNameAndPasswordAndIncludesThemInConnecti
5153
Assert.NotNull(connectionStringResource);
5254
var connectionString = await connectionStringResource.GetConnectionStringAsync();
5355

56+
#pragma warning disable CS0618 // Type or member is obsolete
5457
Assert.Equal($"nats://nats:{natsResource.PasswordParameter?.Value}@localhost:4222", connectionString);
58+
#pragma warning restore CS0618 // Type or member is obsolete
5559
Assert.Equal("nats://nats:{nats-password.value}@{nats.bindings.tcp.host}:{nats.bindings.tcp.port}", connectionStringResource.ConnectionStringExpression.ValueExpression);
5660
}
5761

@@ -68,8 +72,10 @@ public async Task AddNatsSetsUserNameAndPasswordAndIncludesThemInConnection()
6872
Assert.NotNull(nats.Resource.UserNameParameter);
6973
Assert.NotNull(nats.Resource.PasswordParameter);
7074

75+
#pragma warning disable CS0618 // Type or member is obsolete
7176
Assert.Equal("usr", nats.Resource.UserNameParameter!.Value);
7277
Assert.Equal("password", nats.Resource.PasswordParameter!.Value);
78+
#pragma warning restore CS0618 // Type or member is obsolete
7379

7480
using var app = appBuilder.Build();
7581

0 commit comments

Comments
 (0)