#
VContainerThe 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
- Plain C# entry point on own PlayerLoopSystem
- Flexible scoping
- Application can freely create nested Lifetime Scope with any async way for you like.
- Pre IL Code generation optimization mode
- UniTask Integration
- ECS Integration beta
#
DI + Inversion of Control for UnityDI 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 for 10,000 iterations for each test case (Unity 2019.x / IL2CPP Standalone macOS)- By default, both VContainer and Zenject use reflection at runtime.
- "VContainer (CodeGen)" means optimization by pre-generating IL code of Inject methods by ILPostProcessor. See Optimization section for more information.
#
GC Alloc result in the Resolve Complex test case (Unity Editor profiled)#
Basic UsageFirst, 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 asyncLifetimeScope 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.