laravel设计模式

DI与IOC

laravel中实现了DI依赖注入,如:

class UserController
{
    private $user;
    function __construct(UserModel $user) {
        $this->user = $user;
    }
}
$user = new UserController(new UserMonel());

UserController依赖UserModel,在实例化时,laravel会自动主注入UserModel实例。

comments powered by Disqus