laracasts / Commander

Easily leverage commands and domain events in your Laravel projects.
https://laracasts.com/series/commands-and-domain-events
MIT License
279 stars 68 forks source link

Method injection CommandHandler #39

Open reinvanleirsberghe opened 10 years ago

reinvanleirsberghe commented 10 years ago

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?

nesl247 commented 10 years ago

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

JeffreyWay commented 10 years ago

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

bruno-barros commented 10 years ago

And this could be a good Laracast lesson!

johanobergman commented 10 years ago

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.

luisdalmolin commented 9 years ago

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.