[Lumen 5.2 Document] More features--service container

Source: Internet
Author: User

1. Introduction

The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection, which refers to dependency classes injected into code through constructors or "setter" methods.

2, the difference with the Laravel

The lumen and laravel frameworks use the same service container, so for complete documentation on the service container, refer to the Complete Laravel service container documentation.

Accessing Containers

Laravel\lumen\application instances are inherited from Illuminate\container\container and are therefore used as service containers for the application.

Typically, you can register bindings to a container in a service provider, and you can use BIND, singleton, instance, and other methods provided by the container to implement the binding operation.

parsing an instance

To parse an object from a container, you can inject the object with a type hint in a class that the container has automatically resolved, such as a routing closure, controller constructor, controller method, middleware, event listener, or queue task, or you can use the app function to parse directly:

$instance = App (Something::class);
  • 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.