
maui-dependency-injection
Guidance for configuring dependency injection in .NET MAUI apps
by dotnetFree
Description
This agent skill gives guidance on dependency injection in .NET MAUI apps. .NET MAUI uses the same Microsoft.Extensions.DependencyInjection container as ASP.NET Core, and all service registration happens in MauiProgram.CreateMauiApp on builder.Services. The container is built once at startup and does not change afterward, so registrations must be made before that point. The skill covers choosing between AddSingleton, AddTransient and AddScoped, wiring constructor injection into pages and view models, and using Shell navigation to resolve DI-registered pages automatically. It also covers platform-specific service implementations registered with #if directives, and designing interfaces that keep the service layer testable. Data-binding syntax and Shell route registration are handled by other guidance, and mocking and test runners belong to standard .NET testing tools. The skill is for developers setting up the startup code and services of a .NET MAUI app. It is delivered as instructions for a coding agent that edits MauiProgram.cs and your classes.…
Highlights
- Registration in MauiProgram.CreateMauiApp
- Singleton, Transient and Scoped lifetimes
- Constructor injection for pages and view models
- Platform-specific services with #if
Ratings & Reviews
No ratings yet
Be the first to rate maui-dependency-injection.
People also visit
maui-dependency-injection FAQ
Where are services registered?
In MauiProgram.CreateMauiApp, on builder.Services. The container is built once at startup.
How do I choose a lifetime?
The skill compares AddSingleton, AddTransient and AddScoped and explains which fits a given service.
How are platform-specific services handled?
They are registered with #if directives, so each platform gets its own implementation.
How do I install it?
Run npx skills add https://github.com/dotnet/skills --skill maui-dependency-injection in your project.
What are the best maui-dependency-injection alternatives?
Popular alternatives to maui-dependency-injection include dependency-injection, maui-app-lifecycle and maui-safe-area. See all maui-dependency-injection alternatives










