Improve custom resource authoring: WithInitialState defaults, property helpers, and dashboard display
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Is your feature request related to a problem? Please describe the problem.
Improving the authoring experience for custom resources in Aspire. There are friction points with `WithInitialState` and `ResourceNotificationService.PublishUpdateAsync`.
### Current usage example
**WithInitialState:**
```csharp
.WithInitialState(new()
{
ResourceType = "ClockHand",
CreationTimeStamp = DateTime.UtcNow,
State = KnownResourceStates.NotStarted,
Properties =
[
new(CustomResourceKnownProperties.Source, "Talking Clock")
]
});
```
**Pain point:**
- `CreationTimeStamp` should default to `DateTime.UtcNow` so you don't have to specify it for every resource.
- Marking resource as hidden should be easier - https://github.com/dotnet/aspire/issues/6138
- Resources should have default friendly names - https://github.com/dotnet/aspire/issues/5555
**ResourceNotificationService.PublishUpdateAsync:**
```csharp
await notificationService.PublishUpdateAsync(parameterResource, s =>
{
return s with
{
State = new(stateText, KnownResourceStateStyles.Error),
Properties = s.Properties.SetResourceProperty(KnownProperties.Parameter.Value, ex.Message)
};
})
.ConfigureAwait(false);
```
Updates over IResource are a set of immutable snapshots of type [`CustomResourceSnapshot`](src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs). The caller is given the previous update in a callback and they should apply a transformation to that to send a new update.
**Pain points:**
1. `Properties` is a loosely-typed bag ([CustomResourceSnapshot.cs](src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs)), and there are no public helpers for setting them. We need to make [`CustomResourceSnapshotExtensions`](src/Shared/CustomResourceSnapshotExtensions.cs) public so that resource authors have ergonomic helpers.
2. Setting custom properties on resources will not make them show up in the dashboard details view. Authors should be able to mark properties as "important" (e.g. `IsImportant=true`) to have them show up in dashboard details by default. This could be added as a boolean property to `ResourcePropertySnapshot`.
## Describe the solution you'd like
1. Make `CreationTimeStamp` auto-default to `DateTime.UtcNow` in `WithInitialState` if not set.
2. Make `CustomResourceSnapshotExtensions` public to provide helpers for managing resource properties.
3. Add an `IsImportant` boolean property to `ResourcePropertySnapshot` so that custom resource properties can be surfaced in the dashboard details view by default.
- Related to https://github.com/dotnet/aspire/issues/1644
These improvements will make creating and updating custom resources more ergonomic and predictable, and help authors build better Aspire experiences.
## Additional context
- [`TalkingClockResource`](playground/CustomResources/CustomResources.AppHost/TalkingClockResource.cs)
- [`CustomResourceSnapshot`](src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs)
- [`CustomResourceSnapshotExtensions`](src/Shared/CustomResourceSnapshotExtensions.cs)
Contributor guide
Research direction
Start with src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs and src/Shared/CustomResourceSnapshotExtensions.cs, then inspect WithInitialState and the dashboard details handling. Check playground/CustomResources/CustomResources.AppHost/TalkingClockResource.cs for current authoring patterns. Done means the timestamp defaults, property helpers are public, and important custom properties appear in dashboard details.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100