mardi 17 janvier 2017

Singleton with dependency

I have a structure like service, repository etc, in service I inject repository, and service itself is needed to be injected in other class.

In provider I have one RepositoryProvider and one serviceProvider, but when creating singleton service in provider

 $this->app->singleton(SessionService::class, function ($app) {
        return new SessionService(---);
    });

how can I create the service with dependency to the repository, do I have to explicitly create the repository in the creation such as new SessionService(new SessionRepository) doesn't it create a new instance of repository instead of using the repository singleton I created in the repository provider? Is there any way to create singleton with dependencies to other class.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2j3Gpxo
via IFTTT

Aucun commentaire:

Enregistrer un commentaire