[英]How to autowire / autowiring services in nette from the di dependency injection container context
How to autowire nette services from the container, to be accessible to be used inside presenters ( controllers ) or models,etc?如何从容器中自动连接网络服务,以便在演示者(控制器)或模型等内部使用?
To autowire services in Nette to be easily retrievable, used, they must be registered in a config.neon config, or must be those preset by default by framework, in multiple ways:要在 Nette 中自动装配服务以便轻松检索和使用,它们必须在 config.neon 配置中注册,或者必须是框架默认预设的,有多种方式:
use App\Model; // or use App\Model\ArticleRepository;
public function __construct(
Model\ArticlesRepository $articlesRepository,
...
)
{
$this->articlesRepository = $articlesRepository;
/** @var \Nette\Http\Request @inject */ // however , this one is just example, the request service is already available in the presenters via $this->request attribute
public $request;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.