-
Notifications
You must be signed in to change notification settings - Fork 847
Description
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
- Create a TypeScript AppHost with
addRedis - Try to add a custom command via
withCommandthat needs the Redis connection string - Observe that
getConnectionStringAsync()is not available on the resource builder, andExecuteCommandContextonly hasresourceNameandcancellationToken
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)]toRedisResourceand other integration resource types to surface their properties to codegen - Add
[AspireExport]toGetConnectionStringAsynconIResourceWithConnectionString(or add a new exported method) - Consider exposing the resource handle on
ExecuteCommandContextso command callbacks can call methods on the resource
Related: #14772 (closed) covered some overlapping polyglot gaps.