maui-dependency-injection

Configure .NET MAUI dependency injection with service lifetimes and constructor injection.

Updated Nov 27, 2025
One-click install
npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-dependency-injection-seydakaratekeli
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: maui-dependency-injection
Source: https://github.com/seydakaratekeli/KamPay3/tree/main/KamPay/.github/skills/maui-dependency-injection%20-%20Kopyala
Command: npx skills add https://github.com/seydakaratekeli/KamPay3 --skill maui-dependency-injection-seydakaratekeli

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Guidance for dependency injection in .NET MAUI apps — service registration, lifetime decision guidance, constructor injection, and testability best practices.

Core Features & Use Cases

  • Service registration patterns for MAUI: AddSingleton, AddTransient, AddScoped (noting MAUI limitations).
  • Guidance on constructor injection, Shell automatic resolution, and explicit runtime resolution.
  • Platform-specific registration pitfalls and testability considerations with interface-first patterns.

Quick Start

Configure MauiProgram.cs to register services and view models, then navigate via Shell routes to auto-resolve pages.

Frequently Asked Questions about maui-dependency-injection

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

FAQPage Schema
How do I register services and ViewModels for dependency injection in .NET MAUI?

To register services and ViewModels for dependency injection in .NET MAUI, configure the MauiProgram.cs file using AddSingleton, AddTransient, and AddScoped methods to centralize service lifetimes and enable Shell route auto-resolution.

Can I use scoped lifetimes for dependency injection in MAUI Shell navigation?

Using scoped lifetimes for dependency injection in MAUI Shell navigation is generally avoided due to MAUI limitations, requiring explicit constructor injection and careful management of service lifetimes and registration order instead.

What is the best way to resolve platform-specific dependencies in a MAUI app?

The best way to resolve platform-specific dependencies in a MAUI app is to use interface-first patterns for testability, centralizing registrations in MauiProgram.cs while avoiding platform-specific registration pitfalls to ensure clear route-based resolution.

How does Shell route-based resolution work with constructor injection in MAUI?

Shell route-based resolution automatically resolves pages and their constructor injection dependencies in MAUI when services and ViewModels are properly registered in MauiProgram.cs, allowing explicit dependency wiring without manual runtime resolution.

Why does my MAUI dependency injection fail when navigating between Shell routes?

MAUI dependency injection may fail during Shell route navigation due to incorrect service lifetime selection, improper registration order in MauiProgram.cs, or attempting to use scoped lifetimes which MAUI does not fully support.

Do I need interface-first patterns to make MAUI ViewModels testable?

You need interface-first patterns to make MAUI ViewModels testable because they decouple platform-specific implementations, allowing explicit constructor injection of mock dependencies during unit testing while avoiding direct service coupling.