有时候,你可能会有两个类需要用到同一个接口,但是你希望为每个类注入不同的接口实现。例如当我们的系统收到一个新的订单时,我们需要使用 PubNub 来代替 Pusher 发送消息。Laravel 提供了一个简单便利的接口来定义以上的行为:
$this->app->when("AppHandlersCommandsCreateOrderHandler")
->needs("AppContractsEventPusher")
->give("AppServicesPubNubEventPusher");