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.
npx skills add github/awesome-copilot --skill mvvm-toolkit-di --agent copilot
Same command for any agent — swap --agent for claude-code, codex, cursor.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# 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) ```csharp using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using CommunityToolkit.Mvvm.Messaging; public part
- When to use this skill
- Recommended composition root (Generic Host)
- Without Generic Host
- Constructor injection
- Lifetimes
- Resolving in a View
- IMessenger registration
- Keyed services (.NET 8+)
- Testing seams
- Legacy: Ioc.Default
- Common pitfalls
- References
What does the mvvm-toolkit-di skill do?
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.
How do I install it?
Run `npx skills add github/awesome-copilot --skill mvvm-toolkit-di --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From github/awesome-copilot, a repository with 37,432 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.