Showing posts with label Laravel. Show all posts
Showing posts with label Laravel. Show all posts

Wednesday, May 19, 2021

Laravel : Service Container

- a powerful tool for managing class dependencies and performing dependency injection.

- Dependency Injection Container and a Registry for the application


- responsible for managing class dependencies, meaning not every file needs to be injected in class manually but is done by the Service Container automatically.


- Service Container is mainly used in injecting class in controllers like Request object is injected. We can also inject a Model based on id in route binding.


public function profile(Request $request, User $id)

{

    // 

}


In the UserController profile method, the reason we can get the User model as a parameter is because of Service Container as the IoC resolves all the dependencies in all the controllers while booting the server. This process is also called route-model binding.


Request is also one example.



https://medium.com/@digitaldaswani/what-is-service-container-in-laravel-d0dff465f4e0


https://stackoverflow.com/questions/37038830/what-is-the-concept-of-service-container-in-laravel/48239728

DSA Study Path

  How to start learning Data Structures and Algorithms? What are the best resources for learning DSA? Which algorithms are the most importan...