Answer the question
In order to leave comments, you need to log in
Are services initialized at the time of the service call or at the time of the request to the site?
At what point do they initialize?
Will a large number of services affect the speed of the site?
And is it possible to shorten the list using regular expressions (like AppBundle\Model\*Model)
services:
#Models
app.model.companies:
class: AppBundle\Model\CompaniesModel
arguments:
em: "@doctrine.orm.entity_manager"
requestStack: "@request_stack"
app.model.complex:
class: AppBundle\Model\ComplexModel
arguments:
em: "@doctrine.orm.entity_manager"
requestStack: "@request_stack"
app.model.offers:
class: AppBundle\Model\OffersModel
arguments:
em: "@doctrine.orm.entity_manager"
requestStack: "@request_stack"
app.model.posts:
class: AppBundle\Model\PostsModel
arguments:
em: "@doctrine.orm.entity_manager"
requestStack: "@request_stack"
Answer the question
In order to leave comments, you need to log in
symfony.com/doc/current/book/service_container.htm...
~~~
When you ask for the app.mailer service from the container, the container constructs the object and returns it. This is another major advantage of using the service container. Namely, a service is never constructed until it's needed. If you define a service and never use it on a request, the service is never created. This saves memory and increases the speed of your application. This also means that there's very little or no performance hit for defining lots of services. Services that are never used are never constructed.
~~~
ps Just wondering why are you using an entity manager in essence?
The service lifecycle is controlled by the parameter scope
. It can take 2 values: container
(by default) and prototype
. Container
means that a service request from a container will always return the same instance. Prototype
means that the service will be created each time anew. Therefore, most of the services that you create exist in one instance from the beginning of the script to its end.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question