From 20fcfb573951a594f71afaf97678d38d8b05c9f2 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 15 Dec 2022 10:37:27 +0100 Subject: feat(app framework)!: Inject services into controller methods Usually Nextcloud DI goes through constructor injection. This has the implication that each instance of a class builds the full DI tree. That is the injected services, their services, etc. Occasionally there is a service that is only needed for one controller method. Then the DI tree is build regardless if used or not. If services are injected into the method, we only build the DI tree if that method gets executed. This is also how Laravel allows injection. Signed-off-by: Christoph Wurst --- core/Controller/LoginController.php | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) (limited to 'core/Controller/LoginController.php') diff --git a/core/Controller/LoginController.php b/core/Controller/LoginController.php index ef1c1fbd94f..8fd994ae648 100644 --- a/core/Controller/LoginController.php +++ b/core/Controller/LoginController.php @@ -71,7 +71,6 @@ class LoginController extends Controller { private IURLGenerator $urlGenerator; private Defaults $defaults; private Throttler $throttler; - private Chain $loginChain; private IInitialStateService $initialStateService; private WebAuthnManager $webAuthnManager; private IManager $manager; @@ -86,7 +85,6 @@ class LoginController extends Controller { IURLGenerator $urlGenerator, Defaults $defaults, Throttler $throttler, - Chain $loginChain, IInitialStateService $initialStateService, WebAuthnManager $webAuthnManager, IManager $manager, @@ -99,7 +97,6 @@ class LoginController extends Controller { $this->urlGenerator = $urlGenerator; $this->defaults = $defaults; $this->throttler = $throttler; - $this->loginChain = $loginChain; $this->initialStateService = $initialStateService; $this->webAuthnManager = $webAuthnManager; $this->manager = $manager; @@ -290,15 +287,10 @@ class LoginController extends Controller { * @NoCSRFRequired * @BruteForceProtection(action=login) * - * @param string $user - * @param string $password - * @param string $redirect_url - * @param string $timezone - * @param string $timezone_offset - * * @return RedirectResponse */ - public function tryLogin(string $user, + public function tryLogin(Chain $loginChain, + string $user, string $password, string $redirect_url = null, string $timezone = '', @@ -330,7 +322,7 @@ class LoginController extends Controller { $timezone, $timezone_offset ); - $result = $this->loginChain->process($data); + $result = $loginChain->process($data); if (!$result->isSuccess()) { return $this->createLoginFailedResponse( $data->getUsername(), -- cgit v1.2.3