C
C
Cat Anton2015-03-05 11:40:44
Zend Framework
Cat Anton, 2015-03-05 11:40:44

How do lazy services work and why are they needed in Zend Framework 2?

Explain how Lazy Services work and what they are used for in ZF2? I read the documentation, but something has not yet come to a complete understanding. If you throw in specific examples, become or literature, where this is written in more detail, I will be grateful.
framework.zend.com/manual/current/en/modules/zend....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas Lindemann, 2015-03-05
@27cm

"lazy loading" - that is, using the object when necessary, if necessary, it will take the object and load it. In ZF2, this whole thing is resolved through the ServiceManager with the invokables configuration type, where you can place both classes and services directly (essentially the same thing, only the semantics are different). For example, you have created some kind of unique data processing for some particular case, and you want to use it in your module, or even in a specific controller of some module (and then it turned out that you need to use it somewhere else). And this is where "lazy loading" comes to the rescue, where you need to specify a class with unique data processing in the configuration file. Now, as soon as your application needs this functionality (for example, the user requested some resources, which are processed on the server by your unique data processing), then it (ServiceManager) will take this class, that is, load it if necessary. By the way, as I wrote above in parentheses, that you may need to use it somewhere else, then you can go even further, that is, specify the factories type in the configuration file, where to place the previously created factory class implemented using FactoryInterface, and after which means that a class with unique data handling will be created, regardless of possible requirements, only when it was first called, and then you can use it at the level of the entire application. That is, in one place they announced it, called it, and then you call it anywhere and as much as you like. It is worth noting that when you call it again, the same object is returned,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question