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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Projects.ParameterEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
Expand Down
25 changes: 0 additions & 25 deletions src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,4 @@ public static IResourceBuilder<ConnectionStringResource> AddConnectionString(thi
Properties = []
});
}

/// <summary>
/// Adds a connection string to the distributed application a resource with the specified expression.
/// </summary>
/// <remarks>
/// This method also enables appending custom data to the connection string based on other resources that expose connection strings.
/// </remarks>
/// <param name="builder">Distributed application builder</param>
/// <param name="name">The name of the resource.</param>
/// <param name="connectionStringExpression">The connection string expression.</param>
/// <returns>An <see cref="IResourceBuilder{ConnectionStringResource}"/> instance.</returns>
/// <example>
/// <code language="csharp">
/// 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}");
/// </code>
/// </example>
public static IResourceBuilder<ConnectionStringResource> AddConnectionString(this IDistributedApplicationBuilder builder, [ResourceName] string name, ReferenceExpression.ExpressionInterpolatedStringHandler connectionStringExpression)
{
return builder.AddConnectionString(name, ReferenceExpression.Create(connectionStringExpression));
}
}
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Tests/AddParameterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion tests/Aspire.Hosting.Tests/WaitForTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 0 additions & 22 deletions tests/Aspire.Hosting.Tests/WithReferenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>("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()
{
Expand Down
2 changes: 1 addition & 1 deletion tests/TestingAppHost1/TestingAppHost1.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand Down