DI Framework Integrations¶
DxMessaging integrates with three Unity DI frameworks: VContainer, Zenject, and Reflex. This section shows how to bind IMessageBus in each container, use scoped lifetimes for per-scene buses, and inject IMessageRegistrationBuilder so handlers stay testable.
Why Combine DI + Messaging?¶
DI and messaging cover different concerns:
- 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¶
These are setup fragments for the callbacks named below. Each helper registers a new bus for its container. Follow the linked guides to register builders and services.
VContainer¶
Call the helper inside LifetimeScope.Configure(IContainerBuilder builder):
Zenject¶
Call the helper inside MonoInstaller.InstallBindings(), using its Container property:
Reflex¶
Call the helper inside IInstaller.InstallBindings(ContainerBuilder builder):
Configuration at a Glance¶
| Framework | Configuration pattern |
|---|---|
| VContainer | LifetimeScope.Configure and service entry-point registrations |
| Zenject | MonoInstaller.InstallBindings in the context's installer list |
| Reflex | IInstaller.InstallBindings discovered under its ContainerScope |
Common Patterns¶
All frameworks support the same core patterns:
- Global Bus -- Explicitly bind
MessageHandler.MessageBuswhen the container should share the global bus - Scoped Bus -- Register a new bus in each scene or feature container and emit on the bus resolved from that container
- Builder Injection -- Bind
IMessageRegistrationBuilderthrough the framework setup; each independent service owns and disposes its lease - Testable Design -- Use an isolated
MessageBusper test and verify delivery and cleanup
See each framework's guide for detailed examples and best practices.