How are services beneficial to our projects?
If we are creating services in our professional lives (without realizing it), then why don't we feel any difference in our codes?
This is because classes are the body of a service. Without their souls, they are simply another PHP object. Their soul is the concept that gives them birth by instantiating them only if they are needed.
The Dependency Injection Container (or Service Container) is such a concept. It manages the instantiation of services on demand. This means that the service container constructs and returns them once if they are requested. This utilizes memory and application performance in two ways:
If you create a service but never use it, no memory will be wasted for instantiation
If you create a service and use it multiple times, memory will be allocated for the size of one instance only and will be shared across all the instances
This is powerful. Imagine the memory saved in this way.
What if we needed a unique instance of a service?...