Comment

Comment by Danack

>> There is a second form of Dependency Injection that uses setters instead of constructor injection. Do not use this form. >Why?

Not using setter injection eliminates a huge class of bugs that occur when people try to use objects that haven't had all of their dependencies injected yet:

    $user = new RegisteredUser();
    // Any code that touches $user here will be bad
    $user->setEmail($email);
> constructor injection can become a nightmare.

Which is why people use library to do it for them - an example for PHP https://github.com/rdlowrey/auryn.

parent Danack 11 years ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton