spinoza spinoza - 3 years ago 177
PHP Question

Instantiate new class instance inside Symfony services (Best practice)

In Symfony when i create a service and i need an instance of some classes, i pass them as parametre in service or i can create a new instance inside my functions service. I ask this because some Classes constructor needs parametres wich i doesn't have yet when passing the class as parametre.

Answer Source

you pass them as params in service. try to inject your deps to the max and not instantiate directly your services.

see SOLID development principle and particulary in this case Dependency Inversion Principle

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download