composition-root-guard

Enforces Composition Root dependency injection discipline in a C# WinForms application.

Updated Aug 24, 2026
One-click install
npx skills add https://github.com/aggutierrez98/TP-TD --skill composition-root-guard-aggutierrez98
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: composition-root-guard
Source: https://github.com/aggutierrez98/TP-TD/tree/main/.agents/skills/composition-root-guard
Command: npx skills add https://github.com/aggutierrez98/TP-TD --skill composition-root-guard-aggutierrez98

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? It prevents architectural drift in the TpIDS codebase by ensuring all BLL services and transversal services are constructed and injected exclusively through the CompositionRoot class, eliminating hidden Service Locator patterns and duplicate object graphs. ## Core Features & Use Cases - Forbidden Pattern Detection: Blocks new <X>BLL(...) outside CompositionRoot.cs, default constructors on BLLs, and CompositionRoot references inside use-case BLLs. - Dependency Graph Guidance: Provides step-by-step flows for adding new BLLs, transversal SERVICIOS services, and new constructor dependencies while respecting leaf-to-root build order. - Automated Build Guard: Runs a PowerShell verification script on every build via Directory.Build.targets that fails the build on any violation. - Use Case: When adding a new ReportesBLL that depends on BitacoraBLL, follow the skill to declare an internal contract, wire it in CompositionRoot.Inicializar() after its dependencies, and expose a static getter for the UI. ## Quick Start Ask the AI to add a new BLL service or modify an existing BLL constructor while enforcing the Composition Root rules and running the verification script.

Frequently Asked Questions about composition-root-guard

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

FAQPage Schema
How do I add a new BLL class with dependency injection in C#?▼

Create the BLL with a single internal constructor receiving dependencies as interfaces, declare an internal contract in ContratosInternosBLL.cs if other BLLs depend on it, then construct it once in CompositionRoot.Inicializar() after its dependencies and expose a static getter.

What is the Composition Root pattern in dependency injection?▼

Composition Root is the single location where the entire object graph is constructed, triggered once at application startup. Each class receives dependencies via constructor injection, guaranteeing one shared instance per service and explicit, compiler-checked dependencies.

Why is Service Locator considered an anti-pattern in BLL code?▼

Service Locator hides dependencies inside method bodies, making them invisible to the compiler and enabling duplicate object graph construction. Constructor injection makes dependencies explicit and lets the compiler prevent construction outside the root via internal constructors.

How do I enforce architecture rules automatically at build time?▼

Wire a PowerShell verification script into Directory.Build.targets with a custom MSBuild target gated by a property flag. The script scans source files for forbidden patterns like new BLL calls outside the root and fails the build on violations.

Can internal constructors be used for unit testing with mocks?▼

Yes, internal constructors allow injecting test doubles from a test project by adding [assembly: InternalsVisibleTo("<Tests>")] to the BLL AssemblyInfo. This is the intended testing path, avoiding the need for public default constructors.

When should application startup logic not go in CompositionRoot?▼

Functional startup steps like integrity checks or language loading belong in a separate initializer BLL, not CompositionRoot.Inicializar(). The root only composes objects without business side effects, since it is also triggered from the exception handler.