Commander icon indicating copy to clipboard operation
Commander copied to clipboard

Method injection CommandHandler

Open reinvanleirsberghe opened this issue 11 years ago • 5 comments

Hey Jeffrey!

I am trying to do method injection in a CommandHandler class like so: public function handle($command, \UserRepository $userRepository)

Still, I'm getting the following error: Declaration of Site\Registration\RegisterUserCommandHandler::handle() must be compatible with Laracasts\Commander\CommandHandler::handle($command)

Is it even possible to do method injection here?

reinvanleirsberghe avatar Sep 14 '14 08:09 reinvanleirsberghe

No, it isn't possible to do method injection in the CommandHandlers. You can still do dependency injection, but only in the constructor.

nesl247 avatar Sep 18 '14 20:09 nesl247

Not possible right now, but I can add that in, definitely.

JeffreyWay avatar Sep 22 '14 15:09 JeffreyWay

And this could be a good Laracast lesson!

bruno-barros avatar Sep 22 '14 23:09 bruno-barros

Isn't method injection in handlers a bit unnecessary? Their only public interface is the handle() method, so method injection will only be available there anyway.

johanobergman avatar Oct 03 '14 10:10 johanobergman

I think method injection would be cool if we have a way to "SelfHandling" the commands, like L5.

So, a handle method in the Command class will make sense to have dependency injection.

luisdalmolin avatar Jan 26 '15 15:01 luisdalmolin