Return to site
· Service container,web applications,Web Development,Laravel
broken image

The Service Container is a dependency injection container and a registry for application. Instead of creating objects manually the benefits of using Service Container are:

It has the capacity to manage class dependencies. 

In the application you define how an an object should be created and every time an instance need to be created you ask the service container to do it with the required dependencies.

Another advantage is the binding of interfaces to concrete classes.

When an interface is required in a part of the application, the service container instantiates a concrete class  automatically. Changing this concrete class on the binding will change the concrete objects instantiated through all your app.

//everytime a UserRepositoryInterface is requested, create an EloquentUserRepository 

//from now on, create a TestUserRepository