I have a trait and that trait
is being used in controller. In this way, many functions of trait
are being used in Controller
. Controller
is extending a Base Controller. Controller
and BaseController
already have their constructor.
Due to some reasons, I need constructor in trait also because I needed Constructor dependency Injection in trait
. Now, when I place constructor in trait
, constructor does not execute.
In order to overcome this problem, I saw SendsPasswordResetEmails trait
at this location \vendor\laravel\framework\src\Illuminate\Foundation\Auth\SendsPasswordResetEmails.php
. You will see there is function called broker
in this trait
which returns a contract. In this way, they did not need Constructor Dependency Injection because they are getting Contract from the broker
function
I already have a ServiceProvider
which looks like below.
class RoleServiceProvider extends \Illuminate\Support\ServiceProvider {
public function register() {
$this->app->bind(
'App\Architecture\Contract\Role\IRole',
'\App\Architecture\Database\Role\RoleDb'
);
}
public function provides() {
return ['App\Architecture\Contract\Role\IRole'];
}
}
App\Architecture\Contract\Role\IRole
is a Contract. \App\Architecture\Database\Role\RoleDb
is a Database class
Question: Can you kindly tell how would I connect this Service Provide through Facade like it was done in SendsPasswordResetEmails trait
to avoid Constructor Dependency Injection in trait
?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire