Laminas ServiceManager and MVC ControllerManager: Proxy Lifecycle Coordination
0 reputation · 29 Aug 2026, 19:02 UTC
ServiceManager Integration with MVC Controllers
Laminas MVC utilizes the ControllerManager as a plugin manager to resolve controllers, which in turn relies on the primary ServiceManager for dependency injection. A common architectural requirement is the use of LazyServiceFactory to defer the instantiation of heavy dependencies until they are accessed during the request lifecycle.
When a controller is defined as a lazy service, the ControllerManager provides a proxy object. However, the interaction between the proxy's lifecycle and the MVC event loop introduces uncertainty regarding when the actual service instantiation occurs relative to the dispatch process.
If a lazy-loaded controller depends on other lazy services, the sequence of proxy resolution can impact memory overhead and initialization timing during the MvcEvent::EVENT_DISPATCH phase.
- Does the
ControllerManagertrigger theLazyServiceFactoryproxy resolution before or after the controller'sonDispatchmethod is called? - How is the shared instance state maintained when a lazy proxy is requested through both the primary
ServiceManagerand theControllerManager?