[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KR88PDQ2RS394BATJ1142E":3,"skill-same:01M6KR88PDQ2RS394BATJ1142E":79},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":34,"commitSha":35,"skillDirectory":36,"forksCount":37,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":41,"updatedAt":42,"install":43,"resources":56},"01M6KR88PDQ2RS394BATJ1142E","dependency-injection",null,"Use when choosing how systems get their dependencies — autoloads, service locators, @export injection, and scene injection patterns","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28],"dependency injection","dependency","injection","use","dependencies","systems","export","service","patterns","when","2026-11-10 10:12:30",false,"---\nname: dependency-injection\ndescription: Use when choosing how systems get their dependencies — autoloads, service locators, @export injection, and scene injection patterns\n---\n\n# Dependency Injection in Godot 4.3+\n\nPatterns for wiring dependencies between systems so nodes stay loosely coupled, swappable, and testable. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **godot-testing** for test-friendly architecture, **event-bus** for signal-based decoupling, **godot-project-setup** for autoload registration.\n\n---\n\n## 1. The Problem\n\nTight coupling makes code hard to test, extend, and swap. The most common form in Godot is reaching directly into a global autoload from everywhere in the codebase.\n\n```gdscript\n# BAD — tight coupling via direct autoload access scattered everywhere\n\n# player.gd\nfunc take_damage(amount: int) -> void:\n    health -= amount\n    AudioManager.play_sfx(\"hurt\")          # hard dependency on AudioManager\n    UIManager.update_health_bar(health)    # hard dependency on UIManager\n    if health \u003C= 0:\n        GameState.record_death()           # hard dependency on GameState\n\n# enemy.gd\nfunc attack() -> void:\n    AudioManager.play_sfx(\"attack\")        # same AudioManager dependency again\n```\n\n```csharp\n\u002F\u002F BAD — tight coupling via direct autoload \u002F global access scattered everywhere\n\n\u002F\u002F Player.cs\npublic partial class Player : CharacterBody3D\n{\n    private int _health = 100;\n\n    public void TakeDamage(int amount)\n    {\n        _health -= amount;\n        GetNode\u003CAudioService>(\"\u002Froot\u002FAudioManager\").PlaySfx(\"hurt\");        \u002F\u002F hard dependency\n        GetNode\u003CUIManager>(\"\u002Froot\u002FUIManager\").UpdateHealthBar(_health);     \u002F\u002F hard dependency\n        if (_health \u003C= 0)\n            GetNode\u003CGameState>(\"\u002Froot\u002FGameState\").RecordDeath();            \u002F\u002F hard dependency\n    }\n}\n\n\u002F\u002F Enemy.cs\npublic partial class Enemy : CharacterBody3D\n{\n    public void Attack()\n    {\n        GetNode\u003CAudioService>(\"\u002Froot\u002FAudioManager\").PlaySfx(\"attack\");      \u002F\u002F same dependency again\n    }\n}\n```\n\n**Problems with this approach:**\n\n- Every node that calls `AudioManager` directly is coupled to its concrete implementation.\n- Swapping `AudioManager` for a different implementation requires changing every caller.\n- Unit-testing `Player` in isolation is impossible — `AudioManager`, `UIManager`, and `GameState` must all exist and be valid.\n- Autoload initialization order bugs silently break behaviour when scenes load.\n- Hidden dependencies make it hard to see what a class actually needs to function.\n\n---\n\n## 2. Approach Comparison\n\n| Pattern | Complexity | Testability | Best For |\n|---|---|---|---|\n| **Autoloads** | Low | Low | Truly global singletons: audio, settings, platform services |\n| **@export Injection** | Low | High | Most nodes — wire deps in the editor, no runtime lookup needed |\n| **Service Locator** | Medium | Medium | Plugins, optional systems, swappable implementations at runtime |\n| **Scene Injection** | Low | High | Parent-to-child wiring: Level sets up Enemy, HUD sets up sub-panels |\n\n---\n\n## 3. Autoloads as Singletons\n\nRegister a script in **Project Settings → Globals → Autoload** for global access (`AudioManager.play_sfx(...)`, `GameState.score = 100`). Best for cross-cutting concerns: audio, save state, event bus, settings. Resist autoloading domain-specific systems (those should be scene-injected).\n\n> See [references\u002Fautoloads.md](references\u002Fautoloads.md) for the full AudioManager example (SFX + crossfade music) in GDScript + C#. The script's `class_name` (`AudioService`) must differ from the autoload name (`AudioManager`), or Godot reports `hides an autoload singleton`; type injected references as `AudioService`.\n\n---\n\n## 4. @export Node Injection\n\nExpose collaborator nodes as `@export var health_component: HealthComponent`, then wire in the Inspector or via parent scene. Lifecycle: `@export` properties are assigned BEFORE `_ready()`.\n\n> See [references\u002Fexport-injection.md](references\u002Fexport-injection.md) for full `@export` patterns (GDScript + C#) and lifecycle notes.\n\n---\n\n## 5. Service Locator Pattern\n\nA central registry autoload mapping `String` keys to service instances. Services register themselves at `_ready()`, deregister at `_exit_tree()`, consumers call `ServiceLocator.get_service(name)`. Useful when you want flexible runtime swap of implementations (testing, mods, A\u002FB variants).\n\n> See [references\u002Fservice-locator.md](references\u002Fservice-locator.md) for the full Service Locator (GDScript + C#) with typed helper methods.\n\n---\n\n## 6. Scene Injection\n\nParent scene loads its children, then in `_ready()` walks the tree assigning dependencies (`enemy.player = $Player`). Children declare `@export` properties but the parent — not the Inspector — sets them. Best for game-specific dependencies that change per level.\n\n> See [references\u002Fscene-injection.md](references\u002Fscene-injection.md) for the parent-injects-children pattern (GDScript + C#).\n\n---\n\n## 7. Testing with Dependency Injection\n\nInjecting fakes \u002F test doubles is what makes nodes testable. For autoloads: mock-replace before the test scene loads. For `@export` injection: swap the export to a test double. For Service Locator: register a fake under the same key.\n\n> See [references\u002Ftesting-with-di.md](references\u002Ftesting-with-di.md) for GUT-based test patterns showing each injection technique.\n\n---\n\n## 8. When to Use What\n\n| Situation | Recommended Pattern |\n|---|---|\n| Service used by nearly every node in every scene | Autoload singleton |\n| Node needs 1–3 deps, scene is editor-authored | `@export` injection |\n| System is optional or swappable at runtime | Service Locator |\n| Parent scene constructs children and knows their needs | Scene injection |\n| Writing tests for a node with external dependencies | `@export` or property injection + stubs |\n| Plugin that must work in any project | Service Locator (self-registers, no assumptions) |\n| Two sibling nodes need the same dep | Let their parent hold it and inject downward |\n\n**Quick decision guide:**\n\n```\nDoes every scene in the project need it?\n  YES → Autoload singleton\n  NO  ↓\n\nIs the dependency known at edit-time and wired in the Inspector?\n  YES → @export injection\n  NO  ↓\n\nDoes the dependency need to be swapped at runtime (plugins, A\u002FB testing)?\n  YES → Service Locator\n  NO  ↓\n\nDoes a parent scene own both the consumer and the dependency?\n  YES → Scene injection\n  NO  → Reconsider — either promote to autoload or restructure ownership\n```\n\n---\n\n## 9. Anti-patterns\n\n### Autoload for everything\n\n```gdscript\n# BAD — GameManager, EnemySpawner, InventorySystem, DialogueSystem all as autoloads.\n# Every node in the game is coupled to every other system at module level.\n# Test one component → must initialise all autoloads.\n\n# GOOD — Only AudioManager, Settings, and SceneTransition are autoloads.\n# EnemySpawner is a node in the Level scene, injected into enemies that need it.\n```\n\n```csharp\n\u002F\u002F BAD — GameManager, EnemySpawner, InventorySystem, DialogueSystem all as autoloads.\n\u002F\u002F Every node in the game is coupled to every other system at module level.\n\u002F\u002F Test one component → must initialise all autoloads.\n\n\u002F\u002F GOOD — Only AudioManager, Settings, and SceneTransition are autoloads.\n\u002F\u002F EnemySpawner is a node in the Level scene, injected into enemies that need it.\n```\n\n### Deep dependency chains\n\n```gdscript\n# BAD — Player needs HealthComponent, which needs AudioManager,\n# which needs SoundBank, which needs FileSystem...\n# A change deep in the chain breaks everything above it.\n\n# GOOD — flatten: HealthComponent takes only AudioManager (or a narrow interface).\n# Each node declares only immediate dependencies.\n```\n\n```csharp\n\u002F\u002F BAD — Player needs HealthComponent, which needs AudioManager,\n\u002F\u002F which needs SoundBank, which needs FileSystem...\n\u002F\u002F A change deep in the chain breaks everything above it.\n\n\u002F\u002F GOOD — flatten: HealthComponent takes only AudioManager (or a narrow interface).\n\u002F\u002F Each node declares only immediate dependencies.\n```\n\n### Circular dependencies\n\n```gdscript\n# BAD\n# PlayerController._ready() calls ServiceLocator.get_service(\"inventory\")\n# InventorySystem._ready() calls ServiceLocator.get_service(\"player\")\n# Neither can fully initialise because the other isn't ready yet.\n\n# GOOD — break the cycle with a signal.\n# InventorySystem emits item_used; PlayerController connects to it.\n# PlayerController never holds a reference to InventorySystem at all.\n```\n\n```csharp\n\u002F\u002F BAD\n\u002F\u002F PlayerController._Ready() calls ServiceLocator.GetService(\"inventory\")\n\u002F\u002F InventorySystem._Ready() calls ServiceLocator.GetService(\"player\")\n\u002F\u002F Neither can fully initialise because the other isn't ready yet.\n\n\u002F\u002F GOOD — break the cycle with a signal.\n\u002F\u002F InventorySystem emits ItemUsed; PlayerController connects to it.\n\u002F\u002F PlayerController never holds a reference to InventorySystem at all.\n```\n\n### Service Locator as a god object\n\n```gdscript\n# BAD — everything is registered: enemies, UI panels, individual nodes.\n# ServiceLocator becomes a second, untyped scene tree.\n\n# GOOD — only register stable, long-lived services (audio, analytics, save system).\n# Short-lived nodes are wired by their parent via scene injection.\n```\n\n```csharp\n\u002F\u002F BAD — everything is registered: enemies, UI panels, individual nodes.\n\u002F\u002F ServiceLocator becomes a second, untyped scene tree.\n\n\u002F\u002F GOOD — only register stable, long-lived services (audio, analytics, save system).\n\u002F\u002F Short-lived nodes are wired by their parent via scene injection.\n```\n\n### Forgetting null checks after injection\n\n```gdscript\n# BAD — crashes if the @export was never set in the editor\nfunc take_damage(amount: int) -> void:\n    audio.play_sfx(\"hurt\")   # \"Nonexistent function 'play_sfx' in base 'Nil'\" if audio was not wired\n\n# GOOD — guard or assert clearly\nfunc take_damage(amount: int) -> void:\n    assert(audio != null, \"HealthComponent: audio dependency was not injected\")\n    audio.play_sfx(\"hurt\")\n\n# OR — treat it as optional\nfunc take_damage(amount: int) -> void:\n    if audio != null:\n        audio.play_sfx(\"hurt\")\n```\n\n```csharp\n\u002F\u002F BAD — crashes if the [Export] was never set in the editor\npublic void TakeDamage(int amount)\n{\n    _audio.PlaySfx(\"hurt\");   \u002F\u002F NullReferenceException if _audio was not wired\n}\n\n\u002F\u002F GOOD — guard or assert clearly\npublic void TakeDamage(int amount)\n{\n    if (_audio == null)\n    {\n        GD.PushError(\"HealthComponent: audio dependency was not injected\");\n        return;\n    }\n    _audio.PlaySfx(\"hurt\");\n}\n\n\u002F\u002F OR — treat it as optional\npublic void TakeDamage(int amount)\n{\n    _audio?.PlaySfx(\"hurt\");\n}\n```\n\n---\n\n## 10. Checklist\n\n- [ ] Autoloads are used only for genuinely global services (audio, settings, platform)\n- [ ] Nodes declare their dependencies explicitly (`@export` or a public property) rather than calling `get_node` on distant relatives\n- [ ] `@export` fields are validated (`assert` or null check) before use\n- [ ] Service Locator services call `unregister` in `_exit_tree()` \u002F `_ExitTree()`\n- [ ] Scene injection is done in the parent's `_ready()`, after children are fully initialised\n- [ ] No circular dependencies between services or autoloads\n- [ ] Each node depends only on its immediate collaborators — no deep chains\n- [ ] Test stubs\u002Fmocks are plain nodes that implement the same interface as the real service\n- [ ] C# `@export` (`[Export]`) dependencies are disconnected \u002F cleared in `_ExitTree()` if they hold event subscriptions\n- [ ] Service Locator is not used to store scene-specific or short-lived nodes\n","# Dependency Injection in Godot 4.3+\n\nPatterns for wiring dependencies between systems so nodes stay loosely coupled, swappable, and testable. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **godot-testing** for test-friendly architecture, **event-bus** for signal-based decoupling, **godot-project-setup** for autoload registration.\n\n---\n\n## 1. The Problem\n\nTight coupling makes code hard to test, extend, and swap. The most common form in Godot is reaching directly into a global autoload from everywhere in the codebase.\n\n```gdscript\n# BAD — tight coupling via direct autoload access scattered everywhere\n\n# player.gd\nfunc take_damage(amount: int) -> void:\n    health -= amount\n    AudioManager.play_sfx(\"hurt\")          # hard dependency on AudioManager\n    UIManager.update_health_bar(health)    # hard dependency on UIManager\n    if health \u003C= 0:\n        GameState.record_death()           # hard dependency on GameState\n\n# enemy.gd\nfunc attack() -> void:\n    AudioManager.play_sfx(\"attack\")        # same AudioManager dependency again\n```\n\n```csharp\n\u002F\u002F BAD — tight coupling via direct autoload \u002F global access scattered everywhere\n\n\u002F\u002F Player.cs\npublic partial class Player : CharacterBody3D\n{\n    private int _health = 100;\n\n    public void TakeDamage(int amount)\n    {\n        _health -= amount;\n        GetNode\u003CAudioService>(\"\u002Froot\u002FAudioManager\").PlaySfx(\"hurt\");        \u002F\u002F hard dependency\n        GetNode\u003CUIManager>(\"\u002Froot\u002FUIManager\").UpdateHealthBar(_health);     \u002F\u002F hard dependency\n        if (_health \u003C= 0)\n            GetNode\u003CGameState>(\"\u002Froot\u002FGameState\").RecordDeath();            \u002F\u002F hard dependency\n    }\n}\n\n\u002F\u002F Enemy.cs\npublic partial class Enemy : CharacterBody3D\n{\n    public void Attack()\n    {\n        GetNode\u003CAudioService>(\"\u002Froot\u002FAudioManager\").PlaySfx(\"attack\");      \u002F\u002F same dependency again\n    }\n}\n```\n\n**Problems with this approach:**\n\n- Every node that calls `AudioManager` directly is coupled to its concrete implementation.\n- Swapping `AudioManager` for a different implementation requires changing every caller.\n- Unit-testing `Player` in isolation is impossible — `AudioManager`, `UIManager`, and `GameState` must all exist and be valid.\n- Autoload initialization order bugs silently break behaviour when scenes load.\n- Hidden dependencies make it hard to see what a class actually needs to function.\n\n---\n\n## 2. Approach Comparison\n\n| Pattern | Complexity | Testability | Best For |\n|---|---|---|---|\n| **Autoloads** | Low | Low | Truly global singletons: audio, settings, platform services |\n| **@export Injection** | Low | High | Most nodes — wire deps in the editor, no runtime lookup needed |\n| **Service Locator** | Medium | Medium | Plugins, optional systems, swappable implementations at runtime |\n| **Scene Injection** | Low | High | Parent-to-child wiring: Level sets up Enemy, HUD sets up sub-panels |\n\n---\n\n## 3. Autoloads as Singletons\n\nRegister a script in **Project Settings → Globals → Autoload** for global access (`AudioManager.play_sfx(...)`, `GameState.score = 100`). Best for cross-cutting concerns: audio, save state, event bus, settings. Resist autoloading domain-specific systems (those should be scene-injected).\n\n> See [references\u002Fautoloads.md](references\u002Fautoloads.md) for the full AudioManager example (SFX + crossfade music) in GDScript + C#. The script's `class_name` (`AudioService`) must differ from the autoload name (`AudioManager`), or Godot reports `hides an autoload singleton`; type injected references as `AudioService`.\n\n---\n\n## 4. @export Node Injection\n\nExpose collaborator nodes as `@export var health_component: HealthComponent`, then wire in the Inspector or via parent scene. Lifecycle: `@export` properties are assigned BEFORE `_ready()`.\n\n> See [references\u002Fexport-injection.md](references\u002Fexport-injection.md) for full `@export` patterns (GDScript + C#) and lifecycle notes.\n\n---\n\n## 5. Service Locator Pattern\n\nA central registry autoload mapping `String` keys to service instances. Services register themselves at `_ready()`, deregister at `_exit_tree()`, consumers call `ServiceLocator.get_service(name)`. Useful when you want flexible runtime swap of implementations (testing, mods, A\u002FB variants).\n\n> See [references\u002Fservice-locator.md](references\u002Fservice-locator.md) for the full Service Locator (GDScript + C#) with typed helper methods.\n\n---\n\n## 6. Scene Injection\n\nParent scene loads its children, then in `_ready()` walks the tree assigning dependencies (`enemy.player = $Player`). Children declare `@export` properties but the parent — not the Inspector — sets them. Best for game-specific dependencies that change per level.\n\n> See [references\u002Fscene-injection.md](references\u002Fscene-injection.md) for the parent-injects-children pattern (GDScript + C#).\n\n---\n\n## 7. Testing with Dependency Injection\n\nInjecting fakes \u002F test doubles is what makes nodes testable. For autoloads: mock-replace before the test scene loads. For `@export` injection: swap the export to a test double. For Service Locator: register a fake under the same key.\n\n> See [references\u002Ftesting-with-di.md](references\u002Ftesting-with-di.md) for GUT-based test patterns showing each injection technique.\n\n---\n\n## 8. When to Use What\n\n| Situation | Recommended Pattern |\n|---|---|\n| Service used by nearly every node in every scene | Autoload singleton |\n| Node needs 1–3 deps, scene is editor-authored | `@export` injection |\n| System is optional or swappable at runtime | Service Locator |\n| Parent scene constructs children and knows their needs | Scene injection |\n| Writing tests for a node with external dependencies | `@export` or property injection + stubs |\n| Plugin that must work in any project | Service Locator (self-registers, no assumptions) |\n| Two sibling nodes need the same dep | Let their parent hold it and inject downward |\n\n**Quick decision guide:**\n\n```\nDoes every scene in the project need it?\n  YES → Autoload singleton\n  NO  ↓\n\nIs the dependency known at edit-time and wired in the Inspector?\n  YES → @export injection\n  NO  ↓\n\nDoes the dependency need to be swapped at runtime (plugins, A\u002FB testing)?\n  YES → Service Locator\n  NO  ↓\n\nDoes a parent scene own both the consumer and the dependency?\n  YES → Scene injection\n  NO  → Reconsider — either promote to autoload or restructure ownership\n```\n\n---\n\n## 9. Anti-patterns\n\n### Autoload for everything\n\n```gdscript\n# BAD — GameManager, EnemySpawner, InventorySystem, DialogueSystem all as autoloads.\n# Every node in the game is coupled to every other system at module level.\n# Test one component → must initialise all autoloads.\n\n# GOOD — Only AudioManager, Settings, and SceneTransition are autoloads.\n# EnemySpawner is a node in the Level scene, injected into enemies that need it.\n```\n\n```csharp\n\u002F\u002F BAD — GameManager, EnemySpawner, InventorySystem, DialogueSystem all as autoloads.\n\u002F\u002F Every node in the game is coupled to every other system at module level.\n\u002F\u002F Test one component → must initialise all autoloads.\n\n\u002F\u002F GOOD — Only AudioManager, Settings, and SceneTransition are autoloads.\n\u002F\u002F EnemySpawner is a node in the Level scene, injected into enemies that need it.\n```\n\n### Deep dependency chains\n\n```gdscript\n# BAD — Player needs HealthComponent, which needs AudioManager,\n# which needs SoundBank, which needs FileSystem...\n# A change deep in the chain breaks everything above it.\n\n# GOOD — flatten: HealthComponent takes only AudioManager (or a narrow interface).\n# Each node declares only immediate dependencies.\n```\n\n```csharp\n\u002F\u002F BAD — Player needs HealthComponent, which needs AudioManager,\n\u002F\u002F which needs SoundBank, which needs FileSystem...\n\u002F\u002F A change deep in the chain breaks everything above it.\n\n\u002F\u002F GOOD — flatten: HealthComponent takes only AudioManager (or a narrow interface).\n\u002F\u002F Each node declares only immediate dependencies.\n```\n\n### Circular dependencies\n\n```gdscript\n# BAD\n# PlayerController._ready() calls ServiceLocator.get_service(\"inventory\")\n# InventorySystem._ready() calls ServiceLocator.get_service(\"player\")\n# Neither can fully initialise because the other isn't ready yet.\n\n# GOOD — break the cycle with a signal.\n# InventorySystem emits item_used; PlayerController connects to it.\n# PlayerController never holds a reference to InventorySystem at all.\n```\n\n```csharp\n\u002F\u002F BAD\n\u002F\u002F PlayerController._Ready() calls ServiceLocator.GetService(\"inventory\")\n\u002F\u002F InventorySystem._Ready() calls ServiceLocator.GetService(\"player\")\n\u002F\u002F Neither can fully initialise because the other isn't ready yet.\n\n\u002F\u002F GOOD — break the cycle with a signal.\n\u002F\u002F InventorySystem emits ItemUsed; PlayerController connects to it.\n\u002F\u002F PlayerController never holds a reference to InventorySystem at all.\n```\n\n### Service Locator as a god object\n\n```gdscript\n# BAD — everything is registered: enemies, UI panels, individual nodes.\n# ServiceLocator becomes a second, untyped scene tree.\n\n# GOOD — only register stable, long-lived services (audio, analytics, save system).\n# Short-lived nodes are wired by their parent via scene injection.\n```\n\n```csharp\n\u002F\u002F BAD — everything is registered: enemies, UI panels, individual nodes.\n\u002F\u002F ServiceLocator becomes a second, untyped scene tree.\n\n\u002F\u002F GOOD — only register stable, long-lived services (audio, analytics, save system).\n\u002F\u002F Short-lived nodes are wired by their parent via scene injection.\n```\n\n### Forgetting null checks after injection\n\n```gdscript\n# BAD — crashes if the @export was never set in the editor\nfunc take_damage(amount: int) -> void:\n    audio.play_sfx(\"hurt\")   # \"Nonexistent function 'play_sfx' in base 'Nil'\" if audio was not wired\n\n# GOOD — guard or assert clearly\nfunc take_damage(amount: int) -> void:\n    assert(audio != null, \"HealthComponent: audio dependency was not injected\")\n    audio.play_sfx(\"hurt\")\n\n# OR — treat it as optional\nfunc take_damage(amount: int) -> void:\n    if audio != null:\n        audio.play_sfx(\"hurt\")\n```\n\n```csharp\n\u002F\u002F BAD — crashes if the [Export] was never set in the editor\npublic void TakeDamage(int amount)\n{\n    _audio.PlaySfx(\"hurt\");   \u002F\u002F NullReferenceException if _audio was not wired\n}\n\n\u002F\u002F GOOD — guard or assert clearly\npublic void TakeDamage(int amount)\n{\n    if (_audio == null)\n    {\n        GD.PushError(\"HealthComponent: audio dependency was not injected\");\n        return;\n    }\n    _audio.PlaySfx(\"hurt\");\n}\n\n\u002F\u002F OR — treat it as optional\npublic void TakeDamage(int amount)\n{\n    _audio?.PlaySfx(\"hurt\");\n}\n```\n\n---\n\n## 10. Checklist\n\n- [ ] Autoloads are used only for genuinely global services (audio, settings, platform)\n- [ ] Nodes declare their dependencies explicitly (`@export` or a public property) rather than calling `get_node` on distant relatives\n- [ ] `@export` fields are validated (`assert` or null check) before use\n- [ ] Service Locator services call `unregister` in `_exit_tree()` \u002F `_ExitTree()`\n- [ ] Scene injection is done in the parent's `_ready()`, after children are fully initialised\n- [ ] No circular dependencies between services or autoloads\n- [ ] Each node depends only on its immediate collaborators — no deep chains\n- [ ] Test stubs\u002Fmocks are plain nodes that implement the same interface as the real service\n- [ ] C# `@export` (`[Export]`) dependencies are disconnected \u002F cleared in `_ExitTree()` if they hold event subscriptions\n- [ ] Service Locator is not used to store scene-specific or short-lived nodes\n",{"name":5,"description":7},"master","60c28fdc40706a24576731e9fb3508b9c95258ad","skills\u002Fdependency-injection",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add jame581\u002FGodotPrompter --skill dependency-injection",{"tool":49,"command":50},"bunx","bunx skills add jame581\u002FGodotPrompter --skill dependency-injection",{"tool":52,"command":53},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill dependency-injection","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002FSKILL.md",true,[57,63,67,71,75],{"path":58,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002Fautoloads.md","REFERENCE","参考文档",3069,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002Freferences\u002Fautoloads.md",{"path":64,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fexport-injection.md",2616,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002Freferences\u002Fexport-injection.md",{"path":68,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Fscene-injection.md",2402,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002Freferences\u002Fscene-injection.md",{"path":72,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fservice-locator.md",4914,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002Freferences\u002Fservice-locator.md",{"path":76,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Ftesting-with-di.md",4345,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fdependency-injection\u002Freferences\u002Ftesting-with-di.md",[80,100,121,150,174,192],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":29},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[87,88,28,89,90,91,92,93,94,95,96,22,97,98,99],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":101,"name":102,"nameZh":6,"description":103,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":29},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[107,108,109,110,111,112,113,114,22,28,90,115,116,117,118,119,120],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":122,"name":123,"nameZh":6,"description":124,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":125,"categories":126,"keywords":132,"publishedAt":29},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[127],{"categoryNo":128,"categoryName":129,"taxonomyType":130,"taxonomyTypeDesc":131},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[108,25,133,134,135,136,137,138,116,139,140,28,141,142,143,144,145,146,22,147,148,149],"web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":151,"name":152,"nameZh":6,"description":153,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":154,"categories":155,"keywords":164,"publishedAt":29},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[156,159],{"categoryNo":157,"categoryName":158,"taxonomyType":130,"taxonomyTypeDesc":131},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":160,"categoryName":161,"taxonomyType":162,"taxonomyTypeDesc":163},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[90,165,166,167,168,22,169,170,171,172,173],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":175,"name":176,"nameZh":6,"description":177,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":178,"categories":179,"keywords":180,"publishedAt":29},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[181,182,22,183,184,185,186,187,188,189,190,28,191],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","common","implementing","sequences",{"skillNo":193,"name":194,"nameZh":6,"description":195,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":196,"categories":197,"keywords":198,"publishedAt":29},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[199,200,201,90,28,27,202,203,204,205,167,22,190,206],"state","state machine","machine","node","fsm","state machines","trade","trade-offs"]