cakePHP 5: Dependency Injection - Inject existing service into Component

Hello dereuromark,

thank you for your quick response to this. I changed the ComponentRegistry and its working now. Thank you!

But, as you mentioned that it should be simply possible to register the component call itself like:

$container->add(OauthComponent::class);

Thats not working, I got an Exception:

Component App\Controller\Component\OauthComponent is registered in container but cannot be resolved.

So I am doing it like the documentation says:

$container->add(OauthComponent::class)
            ->addArgument(ComponentRegistry::class)
            ->addArgument(GenericProvider::class);


Another bug I just noticed is (and I don’t know if its problem depending on the change in ComponentRegistry), if Controller and Component have same names like

OauthController;
OauthComponent;

I got completely weird results and errors saying:

[Cake\ORM\Exception\MissingTableClassException] Table class for alias Oauth could not be found. in /cakephp/src/ORM/Locator/TableLocator.php on line 249

Exception Attributes: array (
0 => ‘for alias Oauth’,
)

Its weired because I am not using TableLocator anywhere in OauthController or OauthComponent. For now I fixed it changing name of OauthController to something different.