Re: Feature Request: dependencies container
| From: | Marco Pivetta | Date: | Mon, 03 Aug 2020 04:04:58 +0000 |
| Subject: | Re: Feature Request: dependencies container | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111291@lists.php.net to get a copy of this message | ||
Heya,
On Mon, Aug 3, 2020, 05:32 3u93n3 <zsidelnik@gmail.com> wrote:
> The main idea is to take control over objects creation and injecting
> dependencies.
>
> 1. Some of them are provided through constructor (those, which could only
> be retrieved right before instantiating our object).
> 2. Others are provided through
__inject and PHP will inject all
> those
> dependencies automatically. Configuration we define in separate class, and
> pass it's instance into function-helper.
>
Overall, I don't think this is a good candidate for php-src 2 primary
reasons:
1. This is already possible in userland: you can already define your own
__inject method, and, convention-based, rely on it in your own userland
DIC
2. Setter injection (as well as property injection, and also the proposed
__inject) leads to temporal coupling smells. Explained otherwise, your
object instances are not "functioning" right after instantiation, which
makes their API more complex and reduces reliability (they are broken until
injection has happened). Please just use the constructor: it works, and it
is a simple pre-existing injection point 👍