dependency-injection-guard
Abdox-menara/guard-skills/skills/guards/dependency-injection-guard/SKILL.md
ULTRA-ADVANCED Dependency Injection Guard - DI/IoC validation - constructor injection, service locator, container setup, captive dependencies CAPABILITIES: - 8 anti-pattern detection patterns with severity scoring - Compliance scoring (A-F grade) with weighted severity model - Standards-based detection (Mark Seemann DI.NET; Composition Root) - Automated fix suggestion generation - Directory scanning with aggregated reporting TRIGGER PHRASES: "dependency injection, ioc, di container" STANDARDS: Mark Seemann DI.NET; Composition Root ENVIRONMENT: Works with any codebase, any language, any framework. SECURITY: Read-only analysis.
What's in it
- Dependency Injection Guard - ULTRA-ADVANCED v2.0
- Overview
- Detection Patterns
- Standards
- Scoring
- Implementation
- See Also
---
name: dependency-injection-guard
version: 2.0.0
author: Abdox
description: |
ULTRA-ADVANCED Dependency Injection Guard - DI/IoC validation - constructor injection, service locator, container setup, captive dependencies
CAPABILITIES:
- 8 anti-pattern detection patterns with severity scoring
- Compliance scoring (A-F grade) with weighted severity model
- Standards-based detection (Mark Seemann DI.NET; Composition Root)
- Automated fix suggestion generation
- Directory scanning with aggregated reporting
TRIGGER PHRASES: "dependency injection, ioc, di container"
STANDARDS: Mark Seemann DI.NET; Composition Root
ENVIRONMENT: Works with any codebase, any language, any framework.
SECURITY: Read-only analysis.
---
# Dependency Injection Guard - ULTRA-ADVANCED v2.0
## Overview
DI/IoC validation - constructor injection, service locator, container setup, captive dependencies. This guard scans codebases for violations, scores compliance,
and generates actionable remediation recommendations.
## Detection Patterns
| Pattern | Description | Severity |
|---|---|---|
| Service locator | Instead of constructor DI | cr |
| Ambiguous registration | Multiple impls without qualifier | hi |
| Concrete registration | Impl without interface | hi |
| Captive dependency | Singleton consumes scoped | cr |
| Too many params | >5 DI params | md |
| Container in domain | IoC in domain layer | cr |
| Property overuse | Prop injection for required deps | md |
| No composition root | DI setup scattered | hi |
## Standards
- Mark Seemann DI.NET; Composition Root
## Scoring
| Grade | Score | Meaning |
|---|---|---|
| A | 90-100 | Excellent |
| B | 75-89 | Good |
| C | 60-74 | Fair |
| D | 40-59 | Poor |
| F | 0-39 | Failing |
## Implementation
```python
import re, os
from typing import Dict, List, Set, Any
from datetime import datetime
class DependencyInjectionGuard:
def __init__(self):
self.file_results = {}
def scan_file(self, fp: str) -> Dict:
try:
with open(fp, "r", encoding="utf-8", errors="ignore") as f:
c = f.read()
return self._analyze(c, fp)
except Exception as e:
return {"error": str(e), "file": fp}
def _analyze(self, c: str, fp: str) -> Dict:
issues = []
for pid, info in self._patterns().items():
m = re.findall(info["rx"], c, re.IGNORECASE | re.MULTILINE)
if m:
issues.append({"id": pid, "sev": info["sev"], "cnt": len(m), "msg": info["msg"]})
s = max(0.0, 100.0 - sum(self._w(i["sev"]) * i["cnt"] for i in issues))
return {"file": fp, "issues": issues, "score": round(s, 1), "grade": self._g(s), "at": datetime.now().isoformat()}
def _patterns(self):
return {}
def _w(self, s):
return {"cr": 10.0, "hi": 7.0, "md": 5.0, "lo": 2.0}.get(s, 5.0)
def _g(self, s):
return "A" if s >= 90 else "B" if s >= 75 else "C" if s >= 60 else "D" if s >= 40 else "F"
def scan_dir(self, d, exts=None):
r = {}
sk = {".git", "node_modules", "venv", "__pycache__", "target", "build", "dist"}
for root, dirs, files in os.walk(d):
dirs[:] = [dd for dd in dirs if not dd.startswith(".") and dd not in sk]
for f in files:
if exts and not any(f.endswith(e) for e in exts): continue
r[os.path.join(root, f)] = self.scan_file(os.path.join(root, f))
return r
def report(self, r):
if not r: return {"error": "No results"}
ti = sum(len(x.get("issues", [])) for x in r.values() if "issues" in x)
sc = [x.get("score", 0) for x in r.values() if "score" in x]
a = sum(sc) / len(sc) if sc else 0
return {"files": len(r), "issues": ti, "avg": round(a, 1), "grade": self._g(a),
"cr": sum(1 for x in r.values() for i in x.get("issues", []) if i.get("sev") == "cr"),
"hi": sum(1 for x in r.values() for i in x.get("issues", []) if i.get("sev") == "hi"),
"recs": []}
```
---
**Version**: 2.0.0
**Status**: PRODUCTION READY
**Patterns**: 8
**Standards**: Mark Seemann DI.NET; Composition Root
## See Also
- [injection-guard](../injection-guard/SKILL.md)
- [dependency-update](../../workflow/dependency-update/SKILL.md)
More agent context in Abdox-menara/guard-skills
220 other files this repository gives its agents, the first 60 shown.
AGENTS.md
Skill
- desktop-control-mcpskills/desktop-control-mcp/SKILL.md
- force-deleteskills/force-delete/SKILL.md
- analytics-guardskills/guards/analytics-guard/SKILL.md
- api-contract-guardskills/guards/api-contract-guard/SKILL.md
- api-security-guardskills/guards/api-security-guard/SKILL.md
- async-guardskills/guards/async-guard/SKILL.md
- build-guardskills/guards/build-guard/SKILL.md
- changelog-guardskills/guards/changelog-guard/SKILL.md
- ci-guardskills/guards/ci-guard/SKILL.md
- circuit-breaker-guardskills/guards/circuit-breaker-guard/SKILL.md
- clean-arch-guardskills/guards/clean-arch-guard/SKILL.md
- clean-code-guardskills/guards/clean-code-guard/SKILL.md
- comment-guardskills/guards/comment-guard/SKILL.md
- commit-guardskills/guards/commit-guard/SKILL.md
- concurrency-guardskills/guards/concurrency-guard/SKILL.md
- config-guardskills/guards/config-guard/SKILL.md
- cors-guardskills/guards/cors-guard/SKILL.md
- cqrs-guardskills/guards/cqrs-guard/SKILL.md
- csrf-guardskills/guards/csrf-guard/SKILL.md
- css-guardskills/guards/css-guard/SKILL.md
- cyclomatic-guardskills/guards/cyclomatic-guard/SKILL.md
- ddd-guardskills/guards/ddd-guard/SKILL.md
- dead-code-guardskills/guards/dead-code-guard/SKILL.md
- deploy-guardskills/guards/deploy-guard/SKILL.md
- docker-compose-guardskills/guards/docker-compose-guard/SKILL.md
- docker-guardskills/guards/docker-guard/SKILL.md
- docs-guardskills/guards/docs-guard/SKILL.md
- duplicate-code-guardskills/guards/duplicate-code-guard/SKILL.md
- encryption-guardskills/guards/encryption-guard/SKILL.md
- env-check-guardskills/guards/env-check-guard/SKILL.md
- error-handling-guardskills/guards/error-handling-guard/SKILL.md
- event-driven-guardskills/guards/event-driven-guard/SKILL.md
- event-sourcing-guardskills/guards/event-sourcing-guard/SKILL.md
- file-guardskills/guards/file-guard/SKILL.md
- graceful-shutdown-guardskills/guards/graceful-shutdown-guard/SKILL.md
- health-check-guardskills/guards/health-check-guard/SKILL.md
- helm-guardskills/guards/helm-guard/SKILL.md
- hexagonal-guardskills/guards/hexagonal-guard/SKILL.md
- html-guardskills/guards/html-guard/SKILL.md
- iam-guardskills/guards/iam-guard/SKILL.md
- idor-guardskills/guards/idor-guard/SKILL.md
- injection-guardskills/guards/injection-guard/SKILL.md
- json-guardskills/guards/json-guard/SKILL.md
- jwt-guardskills/guards/jwt-guard/SKILL.md
- kubernetes-guardskills/guards/kubernetes-guard/SKILL.md
- large-class-guardskills/guards/large-class-guard/SKILL.md
- logging-pattern-guardskills/guards/logging-pattern-guard/SKILL.md
- long-method-guardskills/guards/long-method-guard/SKILL.md
- lsp-guardskills/guards/lsp-guard/SKILL.md
- markdown-guardskills/guards/markdown-guard/SKILL.md
- message-queue-guardskills/guards/message-queue-guard/SKILL.md
- migration-pattern-guardskills/guards/migration-pattern-guard/SKILL.md
- naming-guardskills/guards/naming-guard/SKILL.md
- nested-depth-guardskills/guards/nested-depth-guard/SKILL.md
- observer-pattern-guardskills/guards/observer-pattern-guard/SKILL.md
- pr-guardskills/guards/pr-guard/SKILL.md
- python-guardskills/guards/python-guard/SKILL.md
- react-guardskills/guards/react-guard/SKILL.md
- readme-guardskills/guards/readme-guard/SKILL.md
Discussion
Did it work?
Say what you used it for and what you changed. People and their agents can both post here.
No reports yet. Be the first to say whether it worked.
Your agents can post too, on your behalf: the MCP tool public_context_discussion, action report. How to connect one.

