Skip to content

Add MVVM dependency graph notifications#1195

Open
bestlux wants to merge 1 commit intoCommunityToolkit:mainfrom
bestlux:codex/mvvm-dependency-graph
Open

Add MVVM dependency graph notifications#1195
bestlux wants to merge 1 commit intoCommunityToolkit:mainfrom
bestlux:codex/mvvm-dependency-graph

Conversation

@bestlux
Copy link
Copy Markdown

@bestlux bestlux commented May 10, 2026

Closes #857

Addresses #959
Addresses #906
Addresses #1168

This PR adds explicit dependency graph support for MVVM source generation through a new [DependsOn] attribute for calculated properties.

The new API lets target-side calculated properties declare the source properties they depend on:

[DependsOn(nameof(FirstName), nameof(LastName))]
public string FullName => $"{FirstName} {LastName}";

The source generator then expands those dependencies for generated observable properties, including transitive dependencies declared through [DependsOn]. Existing [NotifyPropertyChangedFor] behavior remains direct-only for compatibility.

This also adds:

  • inferred command invalidation for [RelayCommand(CanExecute = nameof(SomeBoolProperty))] when the bool property is generated or graph-derived
  • explicit child INotifyPropertyChanged forwarding through [DependsOn(..., NotifyOnSubPropertyChanges = true)]
  • diagnostics for invalid dependency sources, self-dependencies, dependency cycles, and invalid child-notification sources
  • regression tests for graph expansion, command invalidation, child attach/detach behavior, null handling, initially assigned backing fields, and invalid usage diagnostics

PR Checklist

  • Created a feature/dev branch in your fork (vs. submitting directly from a commit on main)
  • Based off latest main branch of toolkit
  • PR doesn't include merge commits (always rebase on top of our main, if needed)
  • Tested code with current supported SDKs
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes
  • Every new API (including internal ones) has full XML docs
  • Code follows all style conventions

Validation

  • dotnet restore .\dotnet.slnx
  • dotnet test .\tests\CommunityToolkit.Mvvm.SourceGenerators.Roslyn4120.UnitTests\CommunityToolkit.Mvvm.SourceGenerators.Roslyn4120.UnitTests.csproj --filter "FullyQualifiedName~DependsOn|FullyQualifiedName~ObservableProperty" --no-restore -v minimal
  • dotnet test .\tests\CommunityToolkit.Mvvm.Roslyn4120.UnitTests\CommunityToolkit.Mvvm.Roslyn4120.UnitTests.csproj --filter "FullyQualifiedName~DependsOn|FullyQualifiedName~ObservableProperty|FullyQualifiedName~RelayCommand" --no-restore -v minimal
  • dotnet build .\dotnet.slnx -c Debug --no-restore
  • dotnet test .\dotnet.slnx --no-build -c Debug -l "console;verbosity=minimal"
  • git diff --check

Other information

The API intentionally uses a new [DependsOn] attribute rather than changing [NotifyPropertyChangedFor] transitivity, so existing behavior remains compatibility-preserving.

@bestlux
Copy link
Copy Markdown
Author

bestlux commented May 10, 2026

@bestlux please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@dotnet-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@dotnet-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@dotnet-policy-service agree company="Microsoft"

Contributor License Agreement

@dotnet-policy-service agree

@bestlux bestlux marked this pull request as ready for review May 10, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Better support for notifying cascading calculated properties

1 participant