Skip to content

TypeScript AppHost: resource properties and connection strings not accessible for custom commands #15334

@maddymontaquila

Description

@maddymontaquila

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Two related gaps prevent writing custom resource commands (e.g., "Clear Redis Cache") from a TypeScript AppHost — a key scenario from the custom resource commands docs:

1. Resource-specific properties not exported to polyglot hosts

RedisResource (and other integration resource types) has useful public properties (PrimaryEndpoint, Host, Port, ConnectionStringExpression, UriExpression) but none are marked with [AspireExport]. The class itself isn't exported either — only the addRedis() extension method is. From TypeScript, a Redis resource only surfaces generic ContainerResource / IResourceWithEndpoints methods.

The infrastructure to fix this already exists — [AspireExport(ExposeProperties = true)] is the pattern used by ExecuteCommandContext and EnvironmentCallbackContext today.

2. No getConnectionStringAsync available from polyglot hosts

In C#, custom commands get the connection string via resource.GetConnectionStringAsync(). This method exists on IResourceWithConnectionString but has no [AspireExport], so it's invisible to polyglot hosts. The ExecuteCommandContext also only exposes resourceName and cancellationToken — no handle to the resource itself.

Expected Behavior

From a TypeScript AppHost, it should be possible to write a custom command that accesses the resource's connection string:

const redis = await builder.addRedis("cache");

await redis.withCommand("clear-cache", "Clear Cache", async (ctx) => {
    const connStr = await redis.getConnectionStringAsync();
    // connect to Redis and FLUSHDB
    return { success: true };
});

Or, alternatively, the ExecuteCommandContext should expose the resource so the callback can access it.

Steps To Reproduce

  1. Create a TypeScript AppHost with addRedis
  2. Try to add a custom command via withCommand that needs the Redis connection string
  3. Observe that getConnectionStringAsync() is not available on the resource builder, and ExecuteCommandContext only has resourceName and cancellationToken

Exceptions (if any)

No exceptions — the APIs simply don't exist in the generated TypeScript SDK.

.NET Version info

.NET SDK 10.0.102
OS: macOS 26.3 (arm64)

Anything else?

Suggested fixes:

  • Add [AspireExport(ExposeProperties = true)] to RedisResource and other integration resource types to surface their properties to codegen
  • Add [AspireExport] to GetConnectionStringAsync on IResourceWithConnectionString (or add a new exported method)
  • Consider exposing the resource handle on ExecuteCommandContext so command callbacks can call methods on the resource

Related: #14772 (closed) covered some overlapping polyglot gaps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packages

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions