Skip to content

Instantly share code, notes, and snippets.

@afscrome
Last active September 10, 2025 19:44
Show Gist options
  • Save afscrome/e549e208a986a8ffefa4b9ccc82dd1a5 to your computer and use it in GitHub Desktop.
Save afscrome/e549e208a986a8ffefa4b9ccc82dd1a5 to your computer and use it in GitHub Desktop.
// Define our initial value
var value = "initial value";
resource
// Important - need to use a lambda here to ensure the latest value is loaded when the app is restarted
.WithEnvironment("Dynamic", () => value)
// Add a custom command, when invoked, this
// 1. uses the interaction service to prompt for a value
// 2. Update the value used in the `WithEnvironment` lambda
// 3. Restarts the resource to force it to pick up the new env var.
.WithCommand("Change Value", "Change Value", async ctx =>
{
var interactionService = ctx.ServiceProvider.GetRequiredService<IInteractionService>();
if (!interactionService.IsAvailable)
{
return CommandResults.Failure("Interaction service is not available.");
}
var input = new InteractionInput
{
Name = "Name",
InputType = InputType.Text,
Required = true,
Placeholder = "my-app"
};
var result = await interactionService.PromptInputAsync("New value", "Enter a value", input, cancellationToken: ctx.CancellationToken);
if (result.Canceled)
{
return CommandResults.Canceled();
}
value = result.Data.Value;
var commandService = ctx.ServiceProvider.GetRequiredService<ResourceCommandService>();
await commandService.ExecuteCommandAsync(resource.Resource.Name, "resource-restart", ctx.CancellationToken);
return CommandResults.Success();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment