Asv.Modeling
Asv.Modeling provides UI-independent building blocks for application models: identity, ordering, trees, focus, change tracking, routed events, navigation, layout persistence, and undo/redo. Types live in the Asv.Modeling namespace. The package targets the framework configured in src/Directory.Build.props, currently net10.0.
Installation
Models opt into small support interfaces and compose controllers instead of inheriting one mandatory model base class. The package depends on Asv.Common; it does not require Avalonia controls or view models.
Choose a guide
Task | Contracts and components | Guide |
|---|---|---|
Expose parent and child relationships |
| |
Dispatch an operation through the hierarchy |
| |
Resolve a model by a stable path and track navigation history | Navigation controllers and paths | |
Save and restore model state | Layout registrations, controllers, and stores | |
Record and replay model changes | Undo controllers, handlers, histories, and stores |
Small support contracts
Contract | Meaning | Application responsibility |
|---|---|---|
| Exposes a read-only | Choose an identity stable enough for the model's lifetime and persistence needs. |
| Exposes integer | Assign order values and decide how equal values are ordered. |
| Exposes | Implement what focus means; the interface itself does not store focus state or select a UI control. |
| Exposes | Maintain the state and define when saving resets it. |
These interfaces do not automatically add navigation, persistence, or undo. Implement and register each required behavior explicitly.
Integration order
Define stable identities and parent/child ownership.
Add routed events when operations must travel through the tree.
Add navigation for resolving nodes and addressing persisted operations.
Register the state required by layout persistence.
Register undo handlers and attach the intended history owner.
A change to a property does not become undoable just because the object supports change tracking. Layout snapshots and undo history also have different lifecycles: one restores application state, while the other records reversible operations.
Lifetime and persistence
The application owns controllers, subscriptions, and persistent stores. Dispose them with their owner and avoid retaining detached nodes through subscriptions. Root-dependent features should follow the attachment rules in Tree.
Keep persisted identifiers, navigation paths, layout keys, and undo change identifiers stable. Renaming them can make saved state or history impossible to resolve even when the C# code still compiles. Thread scheduling and UI-thread transitions belong to the integrating application.
Source and verification
Implementation is under src/Asv.Modeling; examples and tests are under src/Asv.Modeling.Test.