diff --git a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/Program.cs b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/Program.cs index b41a503167b..33330038ffc 100644 --- a/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/Program.cs +++ b/playground/ParameterEndToEnd/ParameterEndToEnd.AppHost/Program.cs @@ -21,7 +21,7 @@ var insertionrows = builder.AddParameter("insertionrows"); -var cs = builder.AddConnectionString("cs", $"sql={db};rows={insertionrows}"); +var cs = builder.AddConnectionString("cs", ReferenceExpression.Create($"sql={db};rows={insertionrows}")); builder.AddProject("api") .WithExternalHttpEndpoints() diff --git a/src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs b/src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs index c7ce662b961..471b459ad14 100644 --- a/src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs +++ b/src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs @@ -50,29 +50,4 @@ public static IResourceBuilder AddConnectionString(thi Properties = [] }); } - - /// - /// Adds a connection string to the distributed application a resource with the specified expression. - /// - /// - /// This method also enables appending custom data to the connection string based on other resources that expose connection strings. - /// - /// Distributed application builder - /// The name of the resource. - /// The connection string expression. - /// An instance. - /// - /// - /// var builder = DistributedApplication.CreateBuilder(args); - /// - /// var endpoint = builder.AddParameter("endpoint", "http://localhost:3452"); - /// var key = builder.AddParameter("key", secret: true); - /// - /// builder.AddConnectionString("myconnection", $"Endpoint={endpoint};Key={key}"); - /// - /// - public static IResourceBuilder AddConnectionString(this IDistributedApplicationBuilder builder, [ResourceName] string name, ReferenceExpression.ExpressionInterpolatedStringHandler connectionStringExpression) - { - return builder.AddConnectionString(name, ReferenceExpression.Create(connectionStringExpression)); - } } diff --git a/tests/Aspire.Hosting.Tests/AddParameterTests.cs b/tests/Aspire.Hosting.Tests/AddParameterTests.cs index 1f79aac493c..1e162630649 100644 --- a/tests/Aspire.Hosting.Tests/AddParameterTests.cs +++ b/tests/Aspire.Hosting.Tests/AddParameterTests.cs @@ -329,7 +329,7 @@ public async Task AddConnectionStringExpressionIsAValueInTheManifest() var key = appBuilder.AddParameter("key", "secretKey", secret: true); // Get the service provider. - appBuilder.AddConnectionString("mycs", $"Endpoint={endpoint};Key={key}"); + appBuilder.AddConnectionString("mycs", ReferenceExpression.Create($"Endpoint={endpoint};Key={key}")); using var app = appBuilder.Build(); diff --git a/tests/Aspire.Hosting.Tests/WaitForTests.cs b/tests/Aspire.Hosting.Tests/WaitForTests.cs index 8a806ba3ac8..12b166cc714 100644 --- a/tests/Aspire.Hosting.Tests/WaitForTests.cs +++ b/tests/Aspire.Hosting.Tests/WaitForTests.cs @@ -125,7 +125,7 @@ public async Task WaitingForConnectionStringResourceWaitsForReferencedResources( using var builder = TestDistributedApplicationBuilder.Create(testOutputHelper); var dependency = builder.AddResource(new CustomResource("test")); - var cs = builder.AddConnectionString("cs", $"{dependency};Timeout=100"); + var cs = builder.AddConnectionString("cs", ReferenceExpression.Create($"{dependency};Timeout=100")); var nginx = builder.AddContainer("nginx", "mcr.microsoft.com/cbl-mariner/base/nginx", "1.22") .WaitFor(cs); diff --git a/tests/Aspire.Hosting.Tests/WithReferenceTests.cs b/tests/Aspire.Hosting.Tests/WithReferenceTests.cs index 1495511f227..43f93802e8f 100644 --- a/tests/Aspire.Hosting.Tests/WithReferenceTests.cs +++ b/tests/Aspire.Hosting.Tests/WithReferenceTests.cs @@ -270,28 +270,6 @@ public async Task ConnectionStringResourceWithExpressiononnectionString() Assert.Equal("Endpoint=http://localhost:3452;Key=secretKey", config["ConnectionStrings__cs"]); } - [Fact] - public async Task ConnectionStringResourceWithInterpolated() - { - using var builder = TestDistributedApplicationBuilder.Create(); - - var endpoint = builder.AddParameter("endpoint", "http://localhost:3452"); - var key = builder.AddParameter("key", "secretKey", secret: true); - - // Get the service provider. - var resource = builder.AddConnectionString("cs", $"Endpoint={endpoint};Key={key}"); - - var projectB = builder.AddProject("projectb") - .WithReference(resource); - - // Call environment variable callbacks. - var config = await EnvironmentVariableEvaluator.GetEnvironmentVariablesAsync(projectB.Resource, DistributedApplicationOperation.Run, TestServiceProvider.Instance).DefaultTimeout(); - - var servicesKeysCount = config.Keys.Count(k => k.StartsWith("ConnectionStrings__")); - Assert.Equal(1, servicesKeysCount); - Assert.Equal("Endpoint=http://localhost:3452;Key=secretKey", config["ConnectionStrings__cs"]); - } - [Fact] public async Task ConnectionStringResourceWithConnectionStringOverwriteName() { diff --git a/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs b/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs index 85ab0adc9c4..152644fbceb 100644 --- a/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs +++ b/tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs @@ -11,7 +11,7 @@ builder.AddConnectionString("cs"); -builder.AddConnectionString("cs2", $"Value={builder.AddParameter("p", "this is a value")}"); +builder.AddConnectionString("cs2", ReferenceExpression.Create($"Value={builder.AddParameter("p", "this is a value")}")); if (args.Contains("--add-redis")) {