Automated summary
Guides implementation of Unity App UI interfaces using the MVVM pattern with dependency injection: ObservableObject, RelayCommand, AppBuilder and service registration.
Strengths
- Shows how to generate change notifications and commands through the [ObservableProperty] and [RelayCommand] attributes
- Covers registering services in AppBuilder.OnConfiguringApp() and the different lifetimes (singleton, transient, scoped)
- Explains data binding between UXML views and ViewModels, with injection via constructor or the [Service] attribute
- Enforces a strict separation of concerns so the view holds no business logic
Limitations
- Tightly coupled to Unity UI Toolkit and the App UI package, so it does not apply to other UI frameworks
- Assumes solid C# knowledge (partial classes, source generators) and the Unity.AppUI.MVVM / Unity.Properties namespaces
- Does not address unit-testing ViewModels or screen-to-screen navigation
Reach for it when building or refactoring a Unity UI Toolkit app with MVVM and you need ViewModels, commands, or dependency injection wiring.
Skip it outside Unity/App UI, or for a static interface that needs neither data binding nor injected services.
Security analysis
SafeThe skill is purely instructional documentation for Unity's App UI MVVM and dependency injection. It contains no shell commands, no network calls, no file-system or credential operations, and nothing obfuscated. The declared tools (Bash, Read, Write, Edit, Glob, Grep) are broad but standard for a coding assistant that would scaffold ViewModels and register services; no instruction in the body tells the agent to use them for anything destructive or exfiltrating.
No concerns found
How this analysis is madeExamples
Create a ViewModel for a settings screen in my Unity App UI project with a player name string and a volume float, using [ObservableProperty], and show me how to bind them to my UXML document.Set up an AppBuilder in my Unity project and register IPlayerService as a singleton and MainViewModel as transient, then inject the service into the ViewModel.Add a [RelayCommand] to my MainViewModel that saves data through an injected service, and bind it to a Button in my UXML.name: app-ui-mvvm description: "Expert for App UI MVVM pattern and dependency injection - ObservableObject, RelayCommand, AppBuilder, service registration, and DI. Use this skill whenever the user wants to create a ViewModel, bind data to UI elements, set up dependency injection, register services, implement commands for button actions, use [ObservableProperty] or [RelayCommand] attributes, create an AppBuilder, or structure their Unity App UI project with the MVVM architecture pattern. Also trigger when the user asks about data binding in UXML, property change notifications, or service lifetimes (transient, singleton, scoped)." allowed-tools: Bash, Read, Write, Edit, Glob, Grep
App UI MVVM & Dependency Injection Expert
Overview
The MVVM (Model-View-ViewModel) pattern is a design pattern that separates user interface from business logic. Combined with Dependency Injection (DI), it creates a powerful architecture for building maintainable, testable, and scalable applications using Unity's UI Toolkit.
When to Use MVVM
Use MVVM when you need to:
- Separate UI concerns from business logic
- Make your code testable and maintainable
- Bind UI elements to data that changes dynamically
- Handle complex user interactions with clean code organization
- Enable designers and developers to work independently
Core Concepts
Model
The Model is a simple data structure containing the data used by business logic. It has no knowledge of the UI.
ViewModel
The ViewModel contains business logic and is responsible for:
- Updating the Model when the user interacts with the View
- Notifying the View when the Model changes (via property notifications)
- Handling commands (user actions like button clicks)
- Managing state and orchestrating operations
ViewModels connect to Views through data binding.
View
The View is the UI layer responsible for displaying data to the user. It should contain:
- Only UI element definitions and styling logic
- Event handlers that invoke ViewModel commands
- Data bindings to ViewModel properties
Views should never contain business logic.
Key Namespaces
Unity.AppUI.MVVM- Core MVVM classes and DIUnity.Properties- Property attributes and binding support
MVVM + Dependency Injection Architecture
┌─────────────────────────────────────────────┐
│ UIToolkitAppBuilder │
│ (Configures app and services) │
└──────────────────┬──────────────────────────┘
│
┌──────────┴──────────┐
│ │
v v
┌─────────┐ ┌──────────────┐
│ App │ │ Service │
│ │ │ Collection │
└────┬────┘ └──────────────┘
│
v
┌──────────────────┐
│ Views (UI) │◄──── Data Binding ◄─── ViewModels
│ │ Commands (Observable,
└──────────────────┘ RelayCommand)
Common Patterns
1. Observable Properties
Mark ViewModel properties with [ObservableProperty] to automatically generate property change notifications:
[ObservableObject]
public partial class MyViewModel
{
[ObservableProperty]
private string _name;
}
2. Relay Commands
Use [RelayCommand] attributes to auto-generate command properties:
[ObservableObject]
public partial class MyViewModel
{
[RelayCommand]
private void SaveData()
{
// Execute command logic
}
}
3. Service Registration
Register services in AppBuilder.OnConfiguringApp():
appBuilder.services.AddSingleton<IMyService, MyService>();
appBuilder.services.AddTransient<MyViewModel>();
4. Service Injection
Inject services via constructor or [Service] attribute:
[ObservableObject]
public partial class MyViewModel
{
[Service]
public IMyService MyService { get; set; }
}
5. Dependent Properties
Use [AlsoNotifyChangeFor] to notify dependent properties:
[ObservableObject]
public partial class MyViewModel
{
[ObservableProperty]
[AlsoNotifyChangeFor(nameof(IsNameEmpty))]
private string _name;
public bool IsNameEmpty => string.IsNullOrEmpty(Name);
}
Best Practices
- Class Declaration: Classes with
[ObservableObject]must bepartial - Field Naming: Observable fields must be private with underscore prefix (
_fieldName) - Constructor Injection: Prefer constructor injection for required dependencies
- Property Injection: Use
[Service]attribute for optional dependencies - Command Naming: Method names for
[RelayCommand]should describe the action (e.g.,SaveData,DeleteItem) - Separation of Concerns: Keep business logic in ViewModels, UI logic in Views
- Service Lifetimes:
- Use
AddSingletonfor stateless services (loggers, factories) - Use
AddTransientfor stateful services (ViewModels, Pages) - Use
AddScopedfor services tied to a specific scope
- Use
Command Patterns
Simple Commands
[RelayCommand]
void DoSomething() { }
Commands with Parameters
[RelayCommand]
void DoSomethingWith(string parameter) { }
Async Commands
[RelayCommand]
async Task DoSomethingAsync()
{
await Task.Delay(1000);
}
Conditional Commands
[RelayCommand(CanExecute = nameof(CanSave))]
void Save() { }
private bool CanSave => !string.IsNullOrEmpty(Name);
Dependency Injection Lifetimes
- Transient: New instance every time it's requested
- Singleton: Same instance for the entire application lifetime
- Scoped: Same instance within a scope, new instance for different scopes
UI Binding
ViewModels expose observable properties and commands that bind to UI elements:
<ui:Button title="Save">
<Bindings>
<ui:DataBinding property="clickable.command" binding-mode="ToTarget" data-source-path="SaveCommand"/>
<ui:DataBinding property="enabledSelf" binding-mode="ToTarget" data-source-path="CanSave"/>
</Bindings>
</ui:Button>
Related Features
- State Management: Redux-like pattern for complex state
- Navigation: Structured page navigation with parameters
- Data Binding: Automatic UI updates from ViewModel changes
- Commands: User action handling via RelayCommand
Reference Documentation
Consult reference.md when you need exact API signatures for ObservableObject, RelayCommand, AppBuilder, or service container methods, full attribute parameter lists, advanced DI patterns like scoped lifetimes, or details on IDependencyInjectionListener and [CreateProperty]. See examples/ for complete MVVM app setups with multiple ViewModels and services.
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/app-ui-mvvm-di-expert-ms2s7buk/download' --output '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md.part' && mv '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md.part' '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
Tools declared by the author (check availability in your agent): Bash, Read, Write, Edit, Glob, Grep
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && test -s '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/app-ui-mvvm' && cp -R '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk' '.claude/skills/app-ui-mvvm'Cursor
test -f '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && test -s '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/app-ui-mvvm' && cp -R '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk' '.cursor/skills/app-ui-mvvm'Codex
test -f '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && test -s '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/app-ui-mvvm' && cp -R '.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk' '.agents/skills/app-ui-mvvm'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/app-ui-mvvm-di-expert-ms2s7buk'openskills read 'app-ui-mvvm-di-expert-ms2s7buk'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/app-ui-mvvm-di-expert-ms2s7buk/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.