I have made a repository pattern app, having a repo and interface:
class UserRepository extends EloquentRepository implements UserRepositoryInterface
{
public function __construct()
{
$this->model = new User();
}
...
}
The repository and interfaces as well as extended class and its interface is registered in service provider and is called on app boot.
The questions I have are:
- Is there a need to watch out for the order of registering? For example, should
EloquentRepositoryclass be loaded before the repo, or does Laravel handle that on its own? - In case I inject
UserRepositoryInterfacein a controller, is the constructor method called automatically even though I didn't really new-up a class? - How long does the DI injection "live"? If I inject it in a page controller which calls some other controller and needs the same dependency, does the constructor call twice then, and operate separately in each controller?
- Is there a difference if I call it like
App::make()instead of DI?