更新时间:2023-12-01 10:23:16
Laravel的IoC容器可让您为不同的类指定不同的解析器.
Laravel's IoC container lets you specify different resolvers for different classes.
使用when()->needs()->give()
流:
$container->when('UserModel')->needs('DAO')->give(function () {
return new DAO('connectionA', 'usernameA', 'passwrodA');
});
$container->when('PostModel')->needs('DAO')->give(function () {
return new DAO('connectionB', 'usernameB', 'passwrodB');
});
请参见文档.查找标题为上下文绑定的部分.
See the docs. Look for the section titled Contextual Binding.