Di container manager

From nlelouche/Unity-SkillForge · View interactive version

Di container manager is an AI agent skill from the GitHub repository nlelouche/Unity-SkillForge. Dependency Injection specialist for decoupled, testable Unity architectures using DI containers.

How to use this skill

Skill file

DI Container Manager

Overview

Dependency Injection for Unity. Create loosely coupled, testable systems where dependencies are injected rather than created directly.

When to Use

Architecture

┌─────────────────────────────────────────────────────────────┐
│                    DI CONTAINER                             │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  Register                          Resolve                  │
│  ┌──────────────┐                 ┌──────────────┐         │
│  │ IAudioService│ ──────────────▶ │ AudioManager │         │
│  │ IInputService│ ──────────────▶ │ InputManager │         │
│  │ ISaveService │ ──────────────▶ │ SaveManager  │         │
│  └──────────────┘                 └──────────────┘         │
│         ↓                                                   │
│  ┌──────────────────────────────────────────────────┐      │
│  │                   PlayerController               │      │
│  │  [Inject] IAudioService _audio;                  │      │
│  │  [Inject] IInputService _input;                  │      │
│  └──────────────────────────────────────────────────┘      │
└─────────────────────────────────────────────────────────────┘

Popular DI Containers

| Container | Features | Recommended |

|-----------|----------|:-----------:|

| VContainer | Fast, lightweight, Unity-optimized | ✅ |

| Zenject | Feature-rich, mature | ✅ |

| Extenject | Zenject fork, maintained | ✅ |

| Manual DI | No container, constructor injection | ⚠️ |

Injection Types

Best Practices

Few-Shot Examples

Example 1: VContainer Registration

User: "Register audio and save services."

Agent:

public class GameLifetimeScope : LifetimeScope
{
    protected override void Configure(IContainerBuilder builder)
    {
        builder.Register<AudioManager>(Lifetime.Singleton).As<IAudioService>();
        builder.Register<SaveManager>(Lifetime.Singleton).As<ISaveService>();
        
        builder.RegisterComponentInHierarchy<PlayerController>();
    }
}

Example 2: Injection

User: "Inject dependencies into PlayerController."

Agent:

public class PlayerController : MonoBehaviour
{
    [Inject] private readonly IAudioService _audio;
    [Inject] private readonly ISaveService _save;
    
    public void TakeDamage(float amount)
    {
        _audio.PlaySound("hit");
        _save.AutoSave();
    }
}

Example 3: Unit Testing

User: "Mock audio service for tests."

Agent:

public class MockAudioService : IAudioService
{
    public bool WasSoundPlayed { get; private set; }
    public void PlaySound(string id) => WasSoundPlayed = true;
}

// In test
var player = new PlayerController(new MockAudioService());
player.TakeDamage(10);
Assert.IsTrue(mockAudio.WasSoundPlayed);

Lifetimes


TDD Contract

⚠️ Legacy Skill — Refactor Pending

Este skill NO tiene tests automatizados aún. El siguiente boilerplate es un punto de partida.

// Escribe estos tests ANTES de implementar:

// Test 1: should [expected behavior] when [condition]
[Test]
public void DiContainerManager_Should{ExpectedBehavior}_When{Condition}()
{{
    // Arrange
    // TODO: Setup test fixtures
    
    // Act
    // TODO: Execute system under test
    
    // Assert
    Assert.Fail("Not implemented — write test first");
}}

// Test 2: should handle [edge case]
[Test]
public void DiContainerManager_ShouldHandle{EdgeCase}()
{{
    // Arrange
    // TODO: Setup edge case scenario
    
    // Act
    // TODO: Execute
    
    // Assert
    Assert.Fail("Not implemented");
}}

// Test 3: should throw when [invalid input]
[Test]
public void DiContainerManager_ShouldThrow_When{InvalidInput}()
{{
    // Arrange
    var invalidInput = default;
    
    // Act & Assert
    Assert.Throws<Exception>(() => {{ /* execute */ }});
}}

Pasos para completar el TDD:

  1. Descomenta los tests above
  2. Implementa la funcionalidad mínima para que compile
  3. Ejecuta los tests — deben fallar (RED)
  4. Implementa la funcionalidad real
  5. Verifica que los tests pasen (GREEN)
  6. Refactorea manteniendo los tests verdes

Nota: Este skill fue marcado como tdd_first: false durante la auditoría v2.0.1. La sección TDD fue agregada automáticamente pero requiere customización manual para reflejar el comportamiento real del skill.

Related Skills

Recommended Package

VContainer - https://github.com/hadashiA/VContainer

Fastest DI container for Unity with minimal allocation.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.