VContainer#
The extra fast DI (Dependency Injection) for Unity Game Engine. "V" means making Unity's initial "U" more thinner and solid..!
- Fast Resolve: Basically 5-10x faster than Zenject.
- Minimum GC Allocation: In Resolve, we have zero allocation without spawned instances.
- Small code size: Few internal types and few .callvirt.
- Assisting correct DI way: Provides simple and transparent API, and carefully select features. This prevents the DI declaration from becoming overly complex.
- Immutable Container: Thread safety and robustness.
Features#
- Constructor Injection / Method Injection / Property & Field Injection
- Dispatch own PlayerLoopSystem
- Flexible scoping
- Application can freely create nested Lifetime Scope with any async way for you like.
- Pre IL Code generation optimization mode
- ECS Integration beta
DI + Inversion of Control for Unity#

DI containers we can make pure C # classes the entry point (not MonoBehaviour). This means that the control flow and other domain logic can be separated from the function of MonoBehaviour as a view component.
Further reading:
Performance#
Benchmark result 10,000 iteration for each test cases (Unity 2019.x / IL2CPP Standalone macOS)#
- By default, both VContainer and Zenject use reflection at runtime.
- "VContainer (CodeGen)" means optimization feature by pre-generation IL code of Inject methods by ILPostProcessor. See Optimization section more information.
GC Alloc result int the Resolve Complex test case (Unity Editor profiled)#
Basic Usage#
First, create a scope. References are automatically resolved for types registered here.
Where definitions of classes are
and
- In this example, the routeSearch of CharacterService is automatically set as the instance of AStarRouteSearch when CharacterService is resolved.
- Further, VContainer can have a Pure C# class as an entry point. (Various timings such as Start, Update, etc. can be specified.) This facilitates "separation of domain logic and presentation".
Flexible Scoping with async#
LifetimeScope can dynamically create children. This allows you to deal with the asynchronous resource loading that often occurs in games.
In addition, you can create a parent-child relationship with LifetimeScope in an Additive scene.