maui-dependency-injection

maui-dependency-injection is a skill for Claude Code, Codex from managedcode/dotnet-skills. It costs 144 tokens per session (3,080 once invoked), scanned A, a copy of maui-dependency-injection, MIT.

Guidance for setting up dependency injection in .NET MAUI, Microsoft’s framework for building apps for platforms such as Android, iOS, and macOS.

In plain words
What is it for?
It helps register services, pages, and view models in MauiProgram.cs, choose service lifetimes, configure platform-specific implementations, and support Shell navigation.
Why use it?
Dependency injection lets app components receive the services they need, making registration consistent and the code easier to test.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit It helps register services, pages, and view models in MauiProgram.cs, choose service lifetimes, configure platform-specific implementations, and support Shell navigation.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/managedcode/dotnet-skills/maui-dependency-injection
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add managedcode/dotnet-skills --skill maui-dependency-injection
Clone the repo
git clone --depth 1 https://github.com/managedcode/dotnet-skills

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for maui-dependency-injection

README.md
[![agentmods](https://agentmods.dev/badge/skills/managedcode/dotnet-skills/maui-dependency-injection/github.svg)](https://agentmods.dev/skills/managedcode/dotnet-skills/maui-dependency-injection)
Your own site
<a href="https://agentmods.dev/skills/managedcode/dotnet-skills/maui-dependency-injection"><img src="https://agentmods.dev/badge/skills/managedcode/dotnet-skills/maui-dependency-injection/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for maui-dependency-injection

Your own site · 80×15
<a href="https://agentmods.dev/skills/managedcode/dotnet-skills/maui-dependency-injection"><img src="https://agentmods.dev/badge/skills/managedcode/dotnet-skills/maui-dependency-injection.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 144 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,080 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin 100% copy Near-identical to another mod in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00144 $0.03080
Opus 5.5 $0.00058 $0.01232
Sonnet 5.5 $0.00029 $0.00616
Haiku 4.5 $0.00014 $0.00308

Measured 2mo ago against content hash 0efbf7b9dd6c, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

maui-dependency-injection scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2mo ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

This is a copy

100% identical to maui-dependency-injection — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.

catalog/Frameworks/Official-DotNet-MAUI/skills/maui-dependency-injection/SKILL.md · 350 lines

How it starts

The opening of the file, as written. The whole thing — 350 lines — stays where its author put it; the contents beside it link to each section on GitHub.

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, Windows) for conditional registrations

Rules That Change the Answer

Situation Do this Why
Registering a Page or ViewModel Prefer AddTransient A fresh instance per navigation avoids stale state, and a Singleton page cannot be re-added to the visual tree after it is removed. Singleton is defensible for a genuinely single-instance page (e.g. a root tab you want to keep warm)
Registering shared/expensive state AddSingleton One instance app-wide (settings, DB connection, HttpClient handler)
Tempted to use AddScoped Use AddTransient (or AddSingleton if sharing is intended) MAUI has no built-in request scope like ASP.NET Core's HTTP pipeline. MAUI does create one IServiceScope per window, so a Scoped service lives as long as that window — and resolved from the root provider it behaves like a Singleton. Neither gives you per-navigation freshness
Navigating to a DI-registered page Register the page and its ViewModel, then Routing.RegisterRoute Shell.Current.GoToAsync resolves the page through DI and injects its constructor dependencies
Platform-specific implementation #if per platform with every platform covered A missing platform branch leaves the service unregistered and throws at resolution time

Read the full file on GitHub · 350 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2mo ago First seen · 350 lines · 144 tokens per session scan A 0efbf7b9dd6c

Subscribe to this mod's changes

maui-dependency-injection is a skill published in the GitHub repository managedcode/dotnet-skills (496 stars, last pushed yesterday), licensed MIT. It adds 144 tokens to every session and 3,080 once invoked, about $0.0006 per session on Opus 5.5. A static security scan graded it A with 0 findings. It is 100% identical to maui-dependency-injection, differing in 0 lines, and is treated as a copy.

Related

Other skills, from other repositories

xamarin-maui-framework-migration

Baseline migration skill for moving Xamarin.Forms solutions or copied modules to .NET MAUI using a create-new-project workflow.

syncfusion/xamarin-maui-migration-skills · 31 tokens

xamarin-maui-platform-specific-migration

Companion migration skill for Android, iOS, and Windows platform-specific tasks when moving Xamarin.Forms code to .NET MAUI.

syncfusion/xamarin-maui-migration-skills · 35 tokens

xamarin-maui-renderer-handler-migration

Companion migration skill for converting Xamarin.Forms custom renderers and effects to .NET MAUI handlers.

syncfusion/xamarin-maui-migration-skills · 30 tokens

android-java-bindings

Write and repair C# bindings for Java/Kotlin Android libraries with .NET for Android. USE FOR: direct/full AAR or JAR bindings, AndroidMavenLibrary, Metadata.xml, Additions, missing generated APIs, Kotlin JVM signatures, binding-generator warnings, CS0535/CS0738/CS0534, duplicate members, EventArgs, listener Handler…

dotnet/maui-labs · 134 tokens

android-slim-bindings

Create Android slim bindings for MAUI/.NET Android. USE FOR: Native Library Interop, thin Kotlin/Java wrapper design, building wrapper AARs with Gradle, Java-friendly callbacks, @JvmStatic, and dependencies of slim wrappers. DO NOT USE FOR: direct/full Java/Kotlin bindings or generated-code/Metadata.xml repairs (use…

dotnet/maui-labs · 96 tokens

maui-notifications-deep-links

Implement MAUI notifications and deep links. USE FOR: local/push notifications, FCM HTTP v1 migration, APNs/Azure Notification Hubs, permission UX, Android channels/POSTNOTIFICATIONS, iOS UNUserNotificationCenter, token lifecycle, notification tap navigation, app links/universal links/URI schemes. DO NOT USE FOR…

dotnet/maui-labs · 90 tokens