Symfony Dependency Injection and Lazy Services

We are using Symfony’s DependencyInjection component, but, we aren’t using the full-stack framework. In fact, the only other Symfony component we currently use is Doctrine.

When I attempted to utilize lazy Services, I installed the symfony/proxy-manager-bridge package as instructed. Since it is a dependency, this also installed the ocramius/proxy-manager package. However, lazy Services still weren’t working. It ends up that I needed to tell the ContainerBuilder which ProxyInstantiator to use:

The RuntimeInstantiator is installed as part of the proxy-manager-bridge, but, I guess it isn’t utilized automatically unless you’re using the full-stack framework. If you don’t tell it to use the RuntimeInstantiator, it will fallback to using the default RealServiceInstantiator.

Anyway, nothing too complex here, but, I had trouble finding anything online, so I figured I’d put this together so that it might help someone else in the future.

Leave a Reply