Agent skill · Data & Analytics

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

dotnetgithub.com/dotnetGitHub ↗
claude-codeMIT
Install
npx skills add dotnet/skills --skill maui-dependency-injection --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 2
SKILL.md size: 14 KB
Bundled scripts: none
Path: plugins/dotnet-maui/skills/maui-dependency-injection/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 4,927
Language: C#
Read our review of the source →

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

From the SKILL.md

# 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

What's inside
Steps it walks through
  1. When to Use
  2. When Not to Use
  3. Inputs
  4. Rules That Change the Answer
  5. Workflow
  6. Lifetime Selection
  7. Registration Pattern in MauiProgram.cs
  8. Constructor Injection
  9. ViewModel → Page Wiring
  10. Shell Navigation Auto-Resolution
  11. Passing parameters to a DI-resolved ViewModel
  12. Platform-Specific Registration
  13. Explicit Resolution (Last Resort)
  14. Interface-First Pattern for Testability
Ships with 1 file
  • references/dependency-injection-api.md
More from skills
All skills →
About this skill
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.

Keep going