lorisleiva / laravel-actions

⚡️ Laravel components that take care of one specific task
https://laravelactions.com
MIT License
2.52k stars 124 forks source link

Action Dependencies not Injected from Container #242

Closed ryantbrown closed 1 year ago

ryantbrown commented 1 year ago

Is it expected behavior that action dependencies are not resolved from the container? For example, given a binding:

/**
 * Register the service provider.
 */
public function register(): void
{
    $this->app->singleton(OauthFactory::class, function ($app) {
        return new OauthManager($app);
    });
}

I would expect to be able to type hint OauthFactory:

public function handle(OauthFactory $oauth, Request $request): RedirectResponse
{
    /** @var string $provider */
    $provider = $request->route('provider');

    return $this->handle($oauth->driver($provider));
}

But instead get an exception: Exception: Argument #1 ($oauth) must be of type Support\Oauth\Contracts\OauthFactory, Support\Oauth\OauthManager given. However, resolving directly from the container works:

public function handle(Request $request): RedirectResponse
{
    /** @var string $provider */
    $provider = $request->route('provider');

    $oauth = app(OauthFactory::class);

    return $oauth->driver($provider)->redirect();
}

What am I missing?

ryantbrown commented 1 year ago

This is user error.