M
M
magary42017-01-25 10:51:53
symfony
magary4, 2017-01-25 10:51:53

Do you get heavy constructors with a large number of parameter injections?

public function __construct(
        Request $request,
        $router,
        Storage $storage,
        $user,
        Session $session,
        TranslatorInterface $translator,
        DocumentRepository $documentRepository,
        \Swift_Mailer $mailer,
        EngineInterface $templating,
        $checkout_email,
        WishlistOrderManager $wishlistOrderManager
    )
    {
        $this->request = $request;
        $this->router = $router;
        $this->storage = $storage;
        $this->user = $user;
        $this->session = $session;
        $this->translator = $translator;
        $this->documentRepository = $documentRepository;
        $this->mailer = $mailer;
        $this->templating = $templating;
        $this->checkout_email = $checkout_email;
        $this->wishlistOrderManager = $wishlistOrderManager;
    }

I just want to inject the container and get everything from there after injection
, I read that they don’t do this so that they don’t depend on the container and in the future it was possible to change the framework,
but with so many dependencies, I see that it’s not so easy to change this framework and I myself don’t believe that this will happen someday
so is it really necessary to be independent of the container?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Skobkin, 2017-01-25
@skobkin

The point is not only independence from the container, but the obviousness of the presence of dependencies. And in minimizing class responsibility. Why does he need to know about the existence of something that he does not need?

A
Alexander Evgenievich, 2017-01-25
@banderos120

is it really necessary to be container independent?

Yes. SOLID.
No, if it is necessary, and due to the specifics of the task, the container is the same class.
In fact, if the constructor is large, it's okay, in principle, if everything is in order, but this is also the first signal of problems in the architecture.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question