unity-vcontainer

Configure VContainer dependency injection for Unity projects.

10|Updated Nov 21, 2025
One-click install
npx skills add https://github.com/creator-hian/claude-code-plugins --skill unity-vcontainer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unity-vcontainer
Source: https://github.com/creator-hian/claude-code-plugins/tree/main/unity-plugin/skills/unity-vcontainer
Command: npx skills add https://github.com/creator-hian/claude-code-plugins --skill unity-vcontainer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides high-performance dependency injection in Unity using VContainer, focusing on service registration, lifetimes, and testable architecture.

Core Features & Use Cases

  • Constructor and method injection
  • Lifetime scopes (Singleton/Transient/Scoped)
  • MonoBehaviour injection and factories
  • Testing with mocks and ADR-friendly patterns

Quick Start

Register a service and inject it into a MonoBehaviour via [Inject].

Frequently Asked Questions about unity-vcontainer

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

FAQPage Schema
How do I set up dependency injection in a Unity project?

Dependency injection in Unity enables decoupled, testable architecture by registering services centrally and injecting them into components. VContainer provides high-performance IoC with constructor and method injection, lifetime management (Singleton, Transient, Scoped), and MonoBehaviour support through [Inject] attributes for clean, maintainable code.

Can I inject dependencies into MonoBehaviours in Unity?

Yes, VContainer supports MonoBehaviour injection via [Inject] attributes on fields and methods, enabling services to be resolved when instances are instantiated. This works alongside factories and lifetime scopes, allowing game objects to access registered services without manual instantiation or ServiceLocator patterns.

What are lifetime scopes in dependency injection, and how do they work?

Lifetime scopes define how long a service instance persists: Singleton creates one instance for the app lifetime, Transient creates a new instance per request, and Scoped creates one per scope boundary. VContainer manages these scopes automatically, ensuring proper cleanup and resource efficiency across your Unity application.

How do I make my Unity code more testable with dependency injection?

Dependency injection enables testability by replacing real services with mocks during tests. VContainer supports constructor injection and multiple registrations, allowing test suites to configure alternative implementations without modifying game code, following SOLID principles for maintainable, mockable architecture.

Does VContainer work with both constructor and method injection?

VContainer supports both patterns: constructor injection for required dependencies and method injection via [Inject] for optional setup. Choose constructor injection for mandatory services and method injection for initialization-time configuration, adapting to your architecture's needs.

What's the best way to register services in a VContainer setup?

Register services in a container configuration class by specifying type, lifetime scope, and factory method if needed. VContainer resolves dependencies by type and scope, supporting both interface-to-implementation mappings and direct concrete registrations for flexible, maintainable service composition.