Alex Kalh ⁄ Create with the <3 build with the mind

Laravel – Service Container – 2. Binding Interfaces To Implementations

Alex Kalh
by Alex Kalh
March 6, 2023
in Laravel : Architecture Concepts

Laravel – Service Container – 2. Binding Interfaces To Implementations

Là cách binding thông dụng nhất, và khuyến khích dùng nhất, giúp đáp ứng việc triển khai Inversion Of Control.

  • Bước 1: Tạo một interface
  • Bước 2: Tạo một class sẽ implements interface vừa tạo.
  • Bước 3: Đăng ký tham chiếu từ interface tới class.

Sau đó, ta có thể inject bị động một instance object của class SmsServices, thông qua `constructor inject`, hoặc `method inject`

Change $concrete.

Bởi tham số `$abstract` được khai báo cho hàm bind() là một interface.
Nên ta có thể thay đổi instance-object, nếu thay đổi `$concrete` class.

Created by

Alex Kalh

Sự tiến bộ của công nghệ là vô hạn. Đổi thay diễn ra hàng ngày, hàng giờ. "Đó là niềm hạnh phúc, cũng là bi ai của một lập trình viên!"

Leavea comment

Your email address will not be published. Required fields are marked *