hashload/horse/horse-dependency-injection
Claude Code and agent skill by hashload/horse
- community
Checking that the SKILL.md file is still in the repository.
Guide for managing request-scoped contextual services and IoC (dependency injection) in Delphi and Lazarus.
Install
npx vskill@latest install hashload/horse/horse-dependency-injectionSKILL.md
The same SKILL.md was published earlier as hashload/horse/horse-dependency-injection.
Horse Contextual Dependency Injection (Request Scope)
1. Request Scope Architecture
The Services property in THorseRequest provides a thread-safe, request-scoped Inversion of Control (IoC) container. This container manages the lifecycle of classes and objects that need to exist only during the execution of a single HTTP request (e.g., database connections, repository patterns, user context).
- Ownership: The container takes ownership (
doOwnsValues := True) of registered instances. - Automatic Disposal: All registered service instances are automatically destroyed when the request finishes, eliminating memory leaks and removing the need for manual
try/finallyblocks inside route handlers.
2. Direct Instance Injection (Add)
Use Add to register an already instantiated object. The container takes ownership and will destroy the instance when the request ends.
3. Lazy Factory Injection (AddFactory)
Use AddFactory to register a factory delegate. The object will only be instantiated at the exact moment Resolve is called (Lazy Loading). Once instantiated, it is cached for subsequent resolves in the same request and destroyed at the end.
This is highly recommended for heavy resources (like database connections) that might not be needed in every execution path of a route.
4. Best Practices for Dependency Injection in Horse
- Avoid Global Resolving: Never resolve services outside the active request flow. The
Servicescontainer belongs exclusively to the thread handling the currentTHorseRequest. - Cast Returned Objects: The
Resolvemethod returns a rawTObjectto preserve compatibility across old Delphi versions. You must cast it to your concrete class (e.g.,TMyService(Req.Services.Resolve(TMyService))). - One Registry Per Class Type: Only one instance or factory can be registered per class type in the same request. Registering a class that is already registered will raise an exception.
- No Manual Frees: Do not call
.FreeorFreeAndNilon objects resolved fromReq.Servicesthat you want to persist until the end of the request.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingdoc/skills/horse-dependency-injection/SKILL.md
Popularity
- Repository stars
- 1,368
- Repository forks
- 244
- 7-day trend score
- 36
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/hashload/horse/horse-dependency-injection)