What is the relationship between "service provider" and "service container" in Laravel?

Source: Internet
Author: User
What is the relationship between "service provider" and "service container" in Laravel?

Reply content:

What is the relationship between "service provider" and "service container" in Laravel?

Container is the carrier of all service, provider's role is to provide a way to register the service to container.

This should be said to be the relationship between three people.

These two days just look again, the same as a rookie to understand their own;
Laravel's service delivery concept is a dependency injection of PHP, and the implementation of dependency injection uses a reflection mechanism .
1. First put the instantiated object of the required class B into an anonymous function, and then put the class and anonymous functions into the container, assuming that the container is an array
2. Assuming that class A is dependent on class B, in the constructor parameter of Class A, the type of the specified parameter is type B
3. When executing Class A, by reflection, knowing that class A relies on Class B, we execute the anonymous function of Class B from the container, get an instantiated object, pass to a to continue execution

The service provider is used to register and store the classes needed in the future into the container.
The role of a service container is to store the required classes, and then take them from the container when they are used somewhere.

These functions are to reduce the dependencies between modules. When used, automatically add in.

Reference: Https://www.insp.top/article/learn-laravel-container

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.