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

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.

agentmods
npx agentmods add skills/managedcode/dotnet-skills/maui-dependency-injection
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.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.svg" alt="Measured on agentmods" 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. Scan, not verified.
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 $0.00144 $0.03080
Opus 5 $0.00072 $0.01540
Sonnet 5 $0.00029 $0.00616
Haiku 4.5 $0.00014 $0.00308

Measured 3d ago against content hash 0efbf7b9dd6c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, 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 3d 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. 3d 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 (477 stars, last pushed 3d ago), licensed MIT. It adds 144 tokens to every session and 3,080 once invoked, about $0.0007 per session on Opus 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.