microsoft / microsoft/aspire

`ResourceSnapshotBuilder` overwrites resource state, rather than merging with other customisations

Open
#13,647 1 comment 0 reactions 0 assignees View on GitHub
area-app-model area-orchestrator
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

`DCPExecutor` continually clobbers any custom state changes you may try to apply via `ResourceNotificationService.PublishUpdateAsync()`

- If I add a custom url snapshot, DCP will remove those - e.g. https://github.com/dotnet/aspire/issues/11603#issuecomment-3672367438
- In my dotnet tool Pr, I wanted to overwrite `ExecArgs`, `AppArgs` and `AppArgsSensitivity` to focus the dashboard on the core tool arguments, not the arguments to `dotnet tool exec`, but I had to do some really janky stuff to restore my changes whenever DCP reverted them - #13168

### Expected Behavior

`ResourceSnapshotBuilder` should better co-operate with other state changers - ideally only updating the state with differences, rather than blindly overwriting the whole lot.

### Steps To Reproduce

Run the following code - you'll initially see the "Hello World" on the nginx resource, but as soon as the resource starts up, the url will disappear.

```cs
builder.AddContainer("nginx", "nginx")
.OnBeforeResourceStarted(async (res, evt, ct) =>
{
await evt.Services.GetRequiredService().PublishUpdateAsync(res, x => x with
{
Urls = [
..x.Urls,
new("Hello World", "http://localhost/", false)
]
});
await Task.Delay(TimeSpan.FromSeconds(5), ct);
});
```

### Exceptions (if any)

_No response_

### .NET Version info

_No response_

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.