Documentation
Lazy Service
Lazy Service
Delay heavy service instantiation until the first time it is requested.
In some cases, you may want to inject a service that is a bit heavy to instantiate, but is not always used inside your object. Configuring lazy services is one answer to this. With a lazy service the container builder will instantiate the service only when we need it (during the container get call method)
YAML
services:
app.mailer:
class: ./App/Mailer
lazy: true
JSON
{
"services": {
"app.mailer": {
"class": "./App/Mailer",
"lazy": true
}
}
}
JS
let definition = new Definition(SomeClass)
definition.lazy = true
container.setDefinition('some_class', definition)
