Resolve controller via container#7
Resolve controller via container#7lordrhodos wants to merge 10 commits intostarweb:reflection-based_dependency_injectionfrom
Conversation
…amic depency parameter
…o interfaces and moving the old constructor dependencies to a interface based resolveController function in the BaseApp
felixsand
left a comment
There was a problem hiding this comment.
I'm not so sure of this approach. It does expose the internals of the Controller a bit too much (thus increase coupling). Also might this not break backward compatibility (for example in the SWS and SCS)?
I think we should set this as "on hold" for now and focus to get the 1.0.0 with dependency injection out as a first step. What do you say?
I am happy for other approaches if we can get propery controllers with DI in the constructors as result. IMO the suggestions in this PR try to minimize the effort to upgrade. One small visibility change which can be fixed very quick and should not be an issue when upgrading. I understand your concern about exposing the constructor and the The new DIC feature should help us move away from the service locator antipattern which in the current implementation is encouraged by the final constructor and no way to support proper DI. IMO al other approaches to realize good DI will be messy. We could try to use setter injection or use the init function, but this will be ugly and I just have not found any good argument why this would be better. If you have another idea I am happy to try it. The interface addition is an important bug fix. The current implementation instantiates the controller here: Line 226 in 780f28b after fetching the controller class from here Lines 236 to 250 in 780f28b If I am not mistaken this class can be anything ... and finally we call the Line 197 in 780f28b without knowing or checking that this method even exists!
I'd say 0.x releases are allowed to introduce breaking changes even for minor versions as of semver:
and I'd say as the migration effort covering the breaking change is very small lets get this into |
|
just saw that the DIC branch adds strict type hinting to the https://github.com/starweb/starlit-app/pull/4/files#diff-cbd75215699157bafdce077e3deff391R187 This fixes above ☝️ mentioned issue with the |
This PR extends the DIC feature with support to resolve the controller instances from the container:
To be able to support constructor based DI and to avoid that a missing
parent::__constructcall would break the supported flow of theAbstractControllerI have decided to remove the final constructor fromAbstractControllerand to implement theBaseAppagainst a newControllerInterface:A new
ViewAwareControllerInterfaceadds support for the View if needed and is implemented by theAbstractController.There is some code duplication in the
AbstractController::fowardmethod setting the required dependencies via setter injection, so maybe a dedicatedControllerResolveror similar would be better.One breaking change has been introduced which can be fixed quite simple when upgrading: the visibility of the
AbstractController::initmethod needed to be change topublic.I am open to suggestions if there is a better way to provide this feature and of course to feedback regarding this approach ;-)