DI Framework Integrations¶
DxMessaging integrates seamlessly with popular Unity dependency injection (DI) frameworks. This section covers how to combine DxMessaging's reactive event system with constructor-based dependency injection for a powerful, scalable architecture.
Why Combine DI + Messaging?¶
Use the best of both worlds:
- Constructor Injection — for service dependencies (repositories, managers, configuration)
- Messaging — for reactive events (damage taken, item collected, game state changes)
This combination provides:
- Explicit dependencies with testable constructors
- Loose coupling between systems via events
- Scoped message buses for scene isolation
- Clean separation of concerns
Supported Frameworks¶
VContainer¶
Fast, lightweight DI with minimal overhead. Features scoped lifetimes for per-scene message buses.
Zenject¶
Feature-rich DI with extensive Unity integration. Supports complex binding scenarios and sub-containers.
Reflex¶
Modern, reflection-free DI designed for performance. Zero-allocation resolution with AOT support.
Choosing a Framework¶
| Framework | Best For | Performance |
|---|---|---|
| VContainer | Most projects, additive scenes | ⭐⭐⭐ Fast |
| Zenject | Complex projects, existing Zenject codebases | ⭐⭐ Good |
| Reflex | Performance-critical, AOT platforms | ⭐⭐⭐ Fastest |
Common Patterns¶
All frameworks support the same core patterns:
- Global Bus — Share
MessageHandler.MessageBusacross all systems - Scoped Bus — Create per-scene buses for isolation
- Builder Injection — Inject
IMessageRegistrationBuilderfor flexible handler registration - Testable Design — Mock
IMessageBusin unit tests
See each framework's guide for detailed examples and best practices.