Usually on Symnfony framework I use the provided depedency Injection container and on Controller I load the models as a service. To be more In detail on a current project I am having the following services.yml
:
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/book/service_container.html
parameters:
# parameter_name: value
services:
# service_name:
# class: AppBundle\Directory\ClassName
# arguments: ["@another_service_name", "plain_value", "%parameter_name%"]
##################### Crud Managers ##########################
pet_manager:
class: AppBundle\Managers\CRUD\PetManager
arguments: ["@doctrine.orm.entity_manager"]
person_manager:
class: AppBundle\Managers\CRUD\PersonManager
arguments: ["@doctrine.orm.entity_manager","@pet_manager"]
############################ Models ###########################
person_model:
class: AppBundle\Models\PersonModel
arguments: ["@person_manager"]
That On my model I have the basic Business Logic and I use managers in order to fetch data from db or for performing third party actions such as interfacing a third party api, handling filesystem etc etc. All managers are getting Injected into the Models via Depedency Injection.
In Symfony on my controller I use:
$personModel = $this->get('person_model');
In order to load the model.
But is this considered a good practice-approach-architecture in order to apply into another frameworks or vanilla php applications? What caveats may have?