Files
MyAiConfiguration/shared/rules/wpf/references/architecture-and-quality.md
T
Julian LechnerandClaude Opus 5.5 6159c6373c
CI / CI configuration security checks (pull_request) Successful in 2s
CI / Capabilities and shell quality (pull_request) Successful in 15s
CI / Python tests and compilation (pull_request) Successful in 36s
CI / QMD unit tests (pull_request) Successful in 7s
CI / Build and inspect generated packages (pull_request) Successful in 16s
CI / Bash integration and installation guards (pull_request) Failing after 51s
CI / PowerShell tests on Ubuntu (pull_request) Failing after 1m45s
CI / Installed client configuration smoke tests (pull_request) Canceled after 1m24s
docs(rules): fix contradictions, update technical rules, enforce rule structure
- Resolve contradictions: authorization is never a skipped "boundary check";
  one browser token policy (BFF/HttpOnly cookies first, RFC 10017); one
  sanitizer-bypass rule; Angular responses are unknown until validated.
- Add security rules for AI/LLM integration and Java XXE, concrete crypto
  and password-hashing parameters, and RFC 8725 JWT validation.
- Update version-dependent guidance after checking official sources:
  Angular 22, TypeScript 6/7, Node 24+, .NET 10/C# 14, JDK 21-25, Spring
  Boot 4; add a Spring Boot and Spring Security topic.
- Give every rule a unique level-1 title and scope line, keep language
  security files to language specifics, and fix routing for inbound vs
  outbound HTTP, XML parsing, and WPF/Angular parent rules.
- Validate rule structure and routing in validate-config.py, with tests.
- Fix CI issues found by a local run: shellcheck directive order, pinned
  ruff rule set, Invoke-Python test mock, CRLF-tolerant package checks,
  Windows-only credential test, and refreshed prompt-budget baselines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 10:51:08 +01:00

78 lines
3.3 KiB
Markdown

# WPF Architecture, Dependency Injection, Testing, and Performance
Apply these rules when structuring a WPF application, wiring dependency injection, testing view models, or optimizing performance. Load the C# rules for language-level guidance.
## Architecture
* Use the C# version the project targets (see the C# coding-style rule; .NET Framework 4.x WPF apps default to C# 7.3). Prefer MVVM for non-trivial views and keep code-behind limited to view-specific behavior.
* Keep UI, application, and domain logic separate. Avoid business logic in views and direct service access from controls.
* Keep dependencies explicit and testable; prefer composition over inheritance and avoid unnecessary abstractions or framework wrappers.
* Avoid direct database access from views or ViewModels.
* Avoid direct HTTP access from controls.
* Keep external integrations behind focused services.
* Avoid circular dependencies.
* Keep feature boundaries clear.
* Do not create shared utility classes for unrelated functionality.
* Keep shared code genuinely reusable.
* Minimize global state.
* Avoid static service access.
## Dependency Injection
Follow the C# architecture rule for general dependency injection, plus:
* Register views and view models as transient unless they hold intentionally shared state; register shared services as singletons only when they are thread-safe and stateless or own deliberately shared state.
* Do not resolve services from `App.Current` or a static container inside view models; inject them.
* Create EF Core contexts per operation through `IDbContextFactory<T>` (see the C# architecture rule).
## Testing
* Keep ViewModels testable without a UI thread where practical.
* Test behavior rather than implementation details.
* Test domain and application logic independently from WPF.
* Avoid brittle tests coupled to XAML structure.
* Keep UI automation tests focused on critical flows.
* Mock external boundaries rather than internal details.
* Keep tests deterministic.
* Avoid real network, database or filesystem dependencies in unit tests unless explicitly intended.
## Code Quality
Follow the C# coding-style and testing rules, plus:
* Treat binding errors as defects: check the debugger output or XAML binding failures diagnostics for failed bindings after UI changes.
## Performance
* Keep the UI thread responsive.
* Minimize visual tree depth.
* Keep virtualization enabled (see the virtualization section of the collections rule).
* Avoid unnecessary bindings.
* Avoid unnecessary converters.
* Avoid unnecessary resource lookups.
* Avoid unnecessary property change notifications.
* Avoid frequent full collection refreshes.
* Avoid loading large datasets eagerly.
* Load images as the images section of the resources rule defines, and freeze `Freezable` objects where practical.
* Reuse immutable resources where appropriate.
* Avoid unnecessary animations.
* Avoid high-frequency timers on the UI thread.
* Measure startup time, UI responsiveness, memory usage and rendering performance before micro-optimizing.
## Performance Priority
Prioritize WPF performance work in this order:
* UI architecture
* UI thread blocking
* Data loading and I/O
* Virtualization
* Visual tree complexity
* Binding and notification frequency
* Rendering and images
* Memory retention and leaks
* Allocations
* CPU micro-optimizations
Never optimize based purely on assumptions.