maui-dependency-injection
Guidance for configuring dependency injection in .NET MAUI apps — service registration in MauiProgram.cs, lifetime selection (Singleton / Transient / Scoped), constructor injection, Shell navigation auto-resolution, platform-specific registrations, and testability patterns. USE FOR: "dependency injection", "DI setup", "AddSingleton", "AddTransient", "AddScoped", "service registration", "constructor injection", "IServiceProvider", "MauiProgram DI", "register services", "BindingContext injection". DO NOT USE FOR: data binding (use maui-data-binding), Shell route configuration (use maui-shell-nav
npx skills add dotnet/skills --skill maui-dependency-injection --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
# Dependency Injection in .NET MAUI .NET MAUI uses the same `Microsoft.Extensions.DependencyInjection` container as ASP.NET Core. All service registration happens in `MauiProgram.CreateMauiApp()` on `builder.Services`. The container is built once at startup and is immutable thereafter. ## When to Use - Registering services, ViewModels, and Pages in `MauiProgram.cs` - Choosing between `AddSingleton`, `AddTransient`, and `AddScoped` - Wiring constructor injection for Pages and ViewModels - Leveraging Shell navigation to auto-resolve DI-registered Pages - Registering platform-specific service implementations with `#if` directives - Designing interfaces for testable service layers ## When Not to Use - XAML data-binding syntax or compiled bindings — use the **maui-data-binding** skill - Shell route registration and query parameters — use the **maui-shell-navigation** skill - Mocking frameworks or test runners — use standard .NET testing tools (xUnit, NUnit, MSTest) and mocking libraries (NSubstitute, Moq) ## Inputs - A .NET MAUI project with a `MauiProgram.cs` file - Knowledge of which services, ViewModels, and Pages need registration - Target platforms (Android, iOS, Mac Catalyst, Wind
- When to Use
- When Not to Use
- Inputs
- Rules That Change the Answer
- Workflow
- Lifetime Selection
- Registration Pattern in MauiProgram.cs
- Constructor Injection
- ViewModel → Page Wiring
- Shell Navigation Auto-Resolution
- Passing parameters to a DI-resolved ViewModel
- Platform-Specific Registration
- Explicit Resolution (Last Resort)
- Interface-First Pattern for Testability
What does the maui-dependency-injection skill do?
Guidance for configuring dependency injection in .NET MAUI apps — service registration in MauiProgram.cs, lifetime selection (Singleton / Transient / Scoped), constructor injection, Shell navigation auto-resolution, platform-specific registrations, and testability patterns. USE FOR: "dependency injection", "DI setup", "AddSingleton", "AddTransient", "AddScoped", "service registration", "constructor injection", "IServiceProvider", "MauiProgram DI", "register services", "BindingContext injection". DO NOT USE FOR: data binding (use maui-data-binding), Shell route configuration (use maui-shell-nav
How do I install it?
Run `npx skills add dotnet/skills --skill maui-dependency-injection --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 dotnet/skills, a repository with 4,927 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.
