Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions developer_manual/basics/dependency_injection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,26 @@ What not to inject:

.. _`reflection`: https://www.php.net/manual/en/book.reflection.php

Optional services
-----------------

.. versionadded:: 28

If an injected dependency can't be found or build, an exception is thrown. This can be avoided by using the a nullable type notation for a dependency:

.. code-block:: php
:emphasize-lines: 6

namespace OCA\MyApp\MyService;

use Some\Service;

class MyService {
public function __construct(private ?Service $service) {
}
}

If ``\Some\Service`` exists and can be built, it will be injected. Else ``MyService`` will receive ``null``.

Accessing the container from anywhere
-------------------------------------
Expand Down