Constructor injection in routes

75 views
Skip to first unread message

Benque Verkoop op Rekening

unread,
Apr 4, 2022, 6:42:45 AM4/4/22
to Fat-Free Framework
Hi, i'am trying to setup an DI with repository patterns. However when i create a controller constructor like:

public function __construct($f3, Actor $actor) {}

i get an error, second param should be object but is array

i tried

public function __construct($f3, $params, Actor $actor) {}

i get an error, third param should be object but is string

i tried

public function __construct($f3, $params, $string, Actor $actor) {}

and got error, 4 params expected 3 given.

I deduced by testing the second param is the route in array and the third param is indeed a string with the called controller->method i setup in my routes. Clearly F3 injects via the routing the 3 params into the controller constructor. (PS: the first param is always \Base object, so i cannot use that one either it seems)

Two questions:  How can i create my own dependency injection within routing? Is that even possible?

Benque Verkoop op Rekening

unread,
Apr 4, 2022, 7:45:33 AM4/4/22
to Fat-Free Framework
Adding:

i see in \Base -> grab() there are traces of $this->hive['CONTAINER'] (containers) and reflections so could it be there is a container system available for injecting?

Op maandag 4 april 2022 om 12:42:45 UTC+2 schreef Benque Verkoop op Rekening:

ikkez

unread,
Apr 25, 2022, 6:17:07 PM4/25/22
to Fat-Free Framework
Yes you can use any PSR-11 compatible container implementation and put that instance to the CONTAINER var to enable it.

Benque Verkoop op Rekening

unread,
Jun 9, 2022, 6:38:14 AM6/9/22
to Fat-Free Framework
Hey Ikkez,

is it possible you provide a syntax example or does this require a lot of code?

Op dinsdag 26 april 2022 om 00:17:07 UTC+2 schreef ikkez:

ikkez

unread,
Jun 10, 2022, 4:36:47 AM6/10/22
to Fat-Free Framework

Benque Verkoop op Rekening

unread,
Jun 16, 2022, 3:51:12 AM6/16/22
to Fat-Free Framework
Cool! I've created a work-a-round and have my datalogic 100% decoupled from my applogic, but this seems more efficient. And Dice was also on my radar to give a go. Thanks.

Op vrijdag 10 juni 2022 om 10:36:47 UTC+2 schreef ikkez:
Reply all
Reply to author
Forward
0 new messages