Skip to content

Synthetic

Mauro Gadaleta edited this page Jun 28, 2023 · 2 revisions

How to Inject Instances into the Container

In some applications, you may need to inject a class instance as service, instead of configuring the container to create a new instance.

YAML
services:
    # synthetic services don't specify a class
    app.synthetic_service:
        synthetic: true
JS
let definition = container.register('app.synthetic_service')
definition.synthetic = true

Now, you can inject the instance in the container using container.set() method:

let instantiatedService = ...;
container.set('app.synthetic_service', instantiatedService);