maui-dependency-injection

Configure dependency injection for .NET MAUI apps with service registration and lifetimes.

Updated May 28, 2026
One-click install
npx skills add https://github.com/ojrojas/AgentsInstructions --skill maui-dependency-injection-ojrojas
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-dependency-injection
Source: https://github.com/ojrojas/AgentsInstructions/tree/main/.claude/skills/dotnet-maui/skills/maui-dependency-injection
Command: npx skills add https://github.com/ojrojas/AgentsInstructions --skill maui-dependency-injection-ojrojas

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the complexities of configuring dependency injection in .NET MAUI applications, ensuring efficient service registration, lifecycle management, and navigation resolution.

Core Features & Use Cases

  • Service Registration: Guide on registering services, ViewModels, and Pages in MauiProgram.cs.
  • Lifetime Management: Instructions on selecting and using AddSingleton, AddTransient, and AddScoped lifetimes.
  • Constructor Injection: Steps for wiring constructor injection for Pages and ViewModels.
  • Shell Navigation: Integration with Shell navigation for auto-resolution of Pages.
  • Platform-Specific Registrations: Techniques for registering platform-specific services.
  • Testability: Strategies for creating testable service layers with interfaces.

Quick Start

Run the 'maui-dependency-injection' skill to learn how to set up Dependency Injection in your .NET MAUI application and register services correctly.

Frequently Asked Questions about maui-dependency-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I configure dependency injection in .NET MAUI?

Dependency injection in .NET MAUI is configured by registering services, ViewModels, and Pages within the MauiProgram.cs file. This wires up the service container for constructor injection and Shell navigation.

What is the difference between AddSingleton, AddTransient, and AddScoped lifetimes in MAUI?

AddSingleton, AddTransient, and AddScoped are dependency injection lifetimes in .NET MAUI that control service instance management. This Skill provides instructions for selecting the appropriate lifetime to handle service lifecycle and navigation resolution.

How do I use constructor injection with Shell navigation in .NET MAUI?

Constructor injection with Shell navigation in .NET MAUI is achieved by registering Pages and ViewModels in MauiProgram.cs. The Shell navigation system then auto-resolves these registered Pages during navigation transitions.

Can I register platform-specific services in a .NET MAUI dependency injection container?

Yes, you can register platform-specific services in a .NET MAUI dependency injection container. The Skill covers techniques for registering these services alongside standard service registration to handle platform-specific implementations.

Do I need to use interfaces for dependency injection in .NET MAUI testing scenarios?

Using interfaces for dependency injection in .NET MAUI testing scenarios allows you to create testable service layers. The Skill provides strategies for interface-based service registration to support application architecture and mocking.

Why does my .NET MAUI service registration fail during Shell navigation resolution?

Service registration fails during Shell navigation resolution in .NET MAUI when Pages or ViewModels are missing from MauiProgram.cs. Ensure all required components are registered with the correct dependency injection lifetimes.