From 4b23f5d53e8a39228580d262c2a7c8c2f9a8ad8d Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 10 May 2022 00:12:22 +0200 Subject: [PATCH] Add section about OCP\Server::get Signed-off-by: Carl Schwan --- developer_manual/basics/dependency_injection.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/developer_manual/basics/dependency_injection.rst b/developer_manual/basics/dependency_injection.rst index 653b7090e..d3efaf34f 100644 --- a/developer_manual/basics/dependency_injection.rst +++ b/developer_manual/basics/dependency_injection.rst @@ -393,3 +393,14 @@ What not to inject: * It is a `pure function `_ .. _`reflection`: https://www.php.net/manual/en/book.reflection.php + + +Accessing the container from anywhere +------------------------------------ + +Sometimes it can be hard to inject some service inside legacy code, in these case +you can use :code:`OCP\Server::get(MyService::class)`. This should only be used in +the last resort, as this makes your code more complicated to unit test and is +considered an anti-pattern. + +