I recently read phalcon, which uses the di dependency injection method. But I don't feel it is convenient to set a rule to automatically load it, I want to know the advantages and disadvantages of the two. I recently read phalcon. He uses the di dependency injection method, but I feel that it is not convenient to set a rule to automatically load it, I don't know what you think, but I want to know the advantages and disadvantages of the two.
Reply content:
I recently read phalcon, which uses the di dependency injection method. But I don't feel it is convenient to set a rule to automatically load it, want to know the advantages and disadvantages of the two
The essence of automatic loading is http://php.net/manual/zh/function.spl-autoload-register.php recommendation specification reference http://www.php-fig.org/PSR-0 PSR-4
Di dependency injection reference
- How PHP programmers understand IoC/DI
- How PHP programmers understand dependency injection containers)
Ioc is used for decoupling. However, no matter how decoupled, automatic loading is required according to certain rules when loading classes in a project.
Decoupling is used to conveniently Replace the specific implementation of a class at any time. The ioc container facilitates initialization when a service class is used.
Reference Article http://www.yuansir-web.com /? P = 1012 & preview = true
Two are two different things.