Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In Aspire 9.5, endpoint property resolution inside WithEnvironment delegates is corrected so that Host and Port each resolve accurately when accessed independently. Previously, accessing only Host returned localhost and only Port returned the host (published) port unless both properties were accessed together.
Version introduced
Aspire 9.5
Previous behavior
Inside a WithEnvironment delegate, accessing Host alone produced localhost instead of the container (resource) name. Accessing Port alone produced the published (host) port. To coerce correct values, some code accessed multiple endpoint properties in a single expression or used combined properties as a workaround.
var redis = builder.AddRedis("redis");
var app = builder.AddContainer("myapp", "mycontainer")
.WithEnvironment(context =>
{
var endpoint = redis.GetEndpoint("tcp");
// Workaround: force evaluation of multiple properties
_ = endpoint.Property(EndpointProperty.HostAndPort);
// Still: Host would resolve to "localhost" unless both Host and Port
// were referenced in certain combinations.
var host = endpoint.Property(EndpointProperty.Host); // "localhost" (incorrect)
var port = endpoint.Property(EndpointProperty.Port); // Published host port, not container port
context.EnvironmentVariables["REDIS_HOST"] = host;
context.EnvironmentVariables["REDIS_PORT"] = port;
})
.WithReference(redis);
New behavior
Each endpoint property now resolves independently and correctly:
Hostresolves to the container (resource) name (for example,redis).Portresolves to the container's internal (target) port.- No combined or chained property access is required.
var redis = builder.AddRedis("redis");
var app = builder.AddContainer("myapp", "mycontainer")
.WithEnvironment(context =>
{
var endpoint = redis.GetEndpoint("tcp");
var host = endpoint.Property(EndpointProperty.Host); // "redis"
var port = endpoint.Property(EndpointProperty.Port); // Container port (e.g., 6379)
context.EnvironmentVariables["REDIS_HOST"] = host;
context.EnvironmentVariables["REDIS_PORT"] = port;
})
.WithReference(redis);
Type of breaking change
This is a behavioral change.
Reason for change
The previous resolution logic forced workarounds that accessed multiple properties to obtain correct values, making configuration unintuitive, and error prone. The fix aligns per-property resolution with developer expectations and eliminates reliance on indirect or combined property accesses.
Recommended action
Remove any workarounds that:
- Access
EndpointProperty.HostAndPortsolely to force evaluation. - Access both
HostandPorttogether to coerce correctHostbehavior. - Depend on the published host port being returned from
EndpointProperty.Port.
Use the individual properties directly:
var endpoint = redis.GetEndpoint("tcp");
var host = endpoint.Property(EndpointProperty.Host); // Container name
var port = endpoint.Property(EndpointProperty.Port); // Container port
If you previously stored the published port for external binding, explicitly retrieve that value via the appropriate API (for example, a published ports collection) instead of relying on EndpointProperty.Port's former behavior.