Timeline for Dependency Injection via Constructor vs Setter
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 6, 2017 at 12:04 | comment | added | schellingerht | Let us continue this discussion in chat. | |
| Apr 6, 2017 at 12:03 | comment | added | marstato |
You could create an implementation of Personable that uses the Request Facade to obtain the name - but i'd consider that ugly :/
|
|
| Apr 6, 2017 at 11:59 | comment | added | schellingerht |
You're absolutely right. I think it's simply solvable by using setters (rather not), or passing as local parameter (without setting as global).
|
|
| Apr 6, 2017 at 11:53 | comment | added | marstato | Having a break at work ;) Thats your issue: in laravel, the applications object tree should be independent from the incoming request (might be good for java, but highly debatable in PHP IMHO). And you want to use request-dependent information in a part of your application that shouldn't do so. I see a few ways to solve the particular issue, but none of them are nice or best practice :/ | |
| Apr 6, 2017 at 11:50 | comment | added | schellingerht |
You're fast ;-) For example from the Request object.
|
|
| Apr 6, 2017 at 11:49 | comment | added | marstato | And where is that name obtained from? | |
| Apr 6, 2017 at 11:48 | comment | added | schellingerht |
Thank you for your answer. Firstly, it's not about decision between implementations. My issue is: I need a name to make an instance of Person. The instance of Person is made in IoC container, because Person is bind (default) to the interface Personable.
|
|
| Apr 6, 2017 at 11:40 | history | edited | marstato | CC BY-SA 3.0 |
added 78 characters in body
|
| Apr 6, 2017 at 11:35 | history | answered | marstato | CC BY-SA 3.0 |