rm-guide-di

Enforce consistent dependency injection and service registration patterns in Blazor apps.

Updated Nov 11, 2023
One-click install
npx skills add https://github.com/michaelvolz/redmuffin.Blazor.StaticWeb --skill rm-guide-di
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rm-guide-di
Source: https://github.com/michaelvolz/redmuffin.Blazor.StaticWeb/tree/main/.opencode/skills/redmuffin-standards/rm-guide-di
Command: npx skills add https://github.com/michaelvolz/redmuffin.Blazor.StaticWeb --skill rm-guide-di

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Uncontrolled dependency injection patterns in Blazor can lead to runtime failures, singleton leaks, and hard-to-test code, so this guidance keeps constructors, components, and services aligned with predictable DI behavior.

Core Features & Use Cases

  • Constructor injection focus: Emphasizes required constructor parameters and discourages instantiating dependencies inside methods when DI can provide them.
  • Blazor component guidance: Reinforces using [Inject] with required for UI components and avoids service locator anti-patterns that hide dependencies.
  • Configuration handling: Recommends IOptions<T> for configuration-bound services instead of passing IConfiguration throughout business logic.
  • Use case: When adding a new service, handler, or component that relies on shared app services, follow these guidelines to register the service properly and wire dependencies cleanly.

Quick Start

Ask the assistant to review a Blazor component or service constructor and ensure it uses required constructor injection, required [Inject] properties, and IOptions for configuration instead of manual instantiation.

Frequently Asked Questions about rm-guide-di

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

FAQPage Schema
How do I enforce constructor injection in Blazor components and services?

Enforce constructor injection in Blazor by requiring dependencies as constructor parameters and using required [Inject] properties for UI components, which avoids manual instantiation and service locator anti-patterns.

Why does scoped-into-singleton cause runtime failures in Blazor dependency injection?

Scoped-into-singleton causes runtime failures because a captive singleton holds a scoped service beyond its intended lifetime, creating shared state and hard-to-test code in Blazor apps.

Should I use IOptions or IConfiguration for Blazor service configuration?

Use IOptions<T> for configuration-bound services instead of passing IConfiguration throughout business logic, ensuring predictable settings access and clean dependency wiring in Blazor apps.

What's the best way to register scoped services in Blazor without causing leaks?

Register scoped services by wiring them through constructor injection with required dependencies and banning service locator patterns, preventing singleton leaks and runtime failures in Blazor apps.

When do I need to review Blazor component constructors for dependency injection patterns?

Review Blazor component constructors when adding a new service or component relying on shared app services, ensuring they use required [Inject] properties and IOptions for configuration.