在服务提供者register方法中,我们可以将接口绑定到实现:
public function register() { App::bind( UserRepositoryInterface::class, EloquentUserRepository::class ); }
从现在开始,每次应用程序需要的实例时UserRepositoryInterface,Laravel都会自动注入的新实例EloquentUserRepository:
//这将返回EloquentUserRepository的实例 $repo = App::make( UserRepositoryInterface:class );