0

I'm using Laravel 7. would like like to inject services into a event listener. Injecting their interfaces through the constructor works fine, but when I add "implements ShouldQueue" to the class so it runs as a job, it sometimes works, but I mainly get " Target [App\Services\INotificationService] is not instantiable while building [App\Listeners\NewOpportunityMessage].

https://laravel.com/docs/7.x/container#resolving says "Additionally, you may type-hint dependencies in the handle method of queued jobs". However if I do this I get a "Too few arguments to function" exception.

https://laravel.com/docs/7.x/events#defining-listeners says "Your event listeners may also type-hint any dependencies they need on their constructors. All event listeners are resolved via the Laravel service container, so dependencies will be injected automatically".

Please advise on the correct way to inject into a queued listener?

2
  • Provide code examples, we don't know what You already have. Links to docs not providing anything, need to know Your case. Commented Jun 7, 2024 at 18:36
  • app(Interface::class) as simple solution Commented Jun 7, 2024 at 19:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.