Agent skill · software engineering · github

mvvm-toolkit-di

Wire CommunityToolkit.Mvvm ViewModels into Microsoft.Extensions.DependencyInjection. Covers the .NET Generic Host composition root, constructor injection, service lifetimes (Singleton / Transient / Scoped), IMessenger registration, resolving ViewModels in Views, keyed services, testing seams, and the legacy Ioc.Default escape hatch. Use across WPF, WinUI 3, .NET MAUI, Uno, and Avalonia.

Why this skill is useful

Provides specific patterns and practices for integrating MVVM Toolkit with Microsoft.Extensions.DependencyInjection, which the AI wouldn't reliably generate on its own.

What it needs

About 4k tokens when loaded. Last updated 2026-08-07. 37,534 stars on the source repository.

What this skill does

CommunityToolkit.Mvvm + Microsoft.Extensions.DependencyInjection The MVVM Toolkit deliberately ships no DI container — it composes with Microsoft.Extensions.DependencyInjection, the same container ASP.NET Core, Worker services, and the .NET Generic Host use. TL;DR. Build the service provider once at startup (prefer Host.CreateDefaultBuilder()). Register services and ViewModels. Inject through constructors. Avoid Ioc.Default.GetService<T>() in user code. --- When to use this skill Standing up the composition root for a new XAML app (WPF, WinUI 3, MAUI, Uno, Avalonia) Choosing service/VM lifetimes Wiring IMessenger once and injecting it into ObservableRecipient ViewModels Resolving a page's ViewModel without coupling to a service locator Diagnosing "Unable to resolve service for type X while attempting to activate Y" For source generators and ViewModel patterns see the mvvm-toolkit skill. For Messenger pub/sub see mvvm-toolkit-messenger. --- Recommended composition root (Generic Host) Generic Host benefits: appsettings.json binding via Microsoft.Extensions.Configuration Logging via Microsoft.Extensions.Logging Hosted services (IHostedService) for background work Scope validation in development builds WPF and Windows Forms must integrate the host lifetime with the app lifetime — see Use the .NET Generic Host in a WPF app. …

How to use it

Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:

@skills github/mvvm-toolkit-di

View the source on GitHub

Browse the @skills marketplace