AgentSkillsCN

dependency-injection-dotnet

适用于应用 .NET 依赖注入模式、服务生命周期,以及通过 Microsoft.Extensions.DependencyInjection 或等效方式实现组件化时使用。

SKILL.md
--- frontmatter
name: dependency-injection-dotnet
description: Use when applying .NET dependency injection patterns, service lifetimes, and composition via Microsoft.Extensions.DependencyInjection or equivalent.
  • If the current project is not .NET-based, ignore this skill.
  • If the current project is not .NET-based, ignore this skill.
  • Use constructor injection as the default pattern
  • Prefer explicit service registration over service locators
  • Respect service lifetimes (Singleton, Scoped, Transient)
  • Avoid static/global dependencies where possible
  • Favor DI-friendly APIs and testable design

Framework guidance:

  • .NET: Microsoft.Extensions.DependencyInjection
  • Generic Host patterns are acceptable when appropriate
  • Do not introduce alternative DI containers unless explicitly approved in PROJECT or PRD