From 6b1ac0ae1044f04175b629f0fb5a10b77887903f Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Wed, 19 Dec 2018 10:31:45 +0100 Subject: [PATCH] Add a note to the container docs Just so people are directed to the proper section. most people should not have to register services on their own. Signed-off-by: Roeland Jago Douma --- developer_manual/app/requests/container.rst | 22 ++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/developer_manual/app/requests/container.rst b/developer_manual/app/requests/container.rst index 18c094b81..9c927db64 100644 --- a/developer_manual/app/requests/container.rst +++ b/developer_manual/app/requests/container.rst @@ -4,7 +4,9 @@ Container .. sectionauthor:: Bernhard Posselt -The App Framework assembles the application by using a container based on the software pattern `Dependency Injection `_. This makes the code easier to test and thus easier to maintain. +The App Framework assembles the application by using a container based on the +software pattern `Dependency Injection `_. +This makes the code easier to test and thus easier to maintain. If you are unfamiliar with this pattern, watch the following videos: @@ -16,7 +18,8 @@ If you are unfamiliar with this pattern, watch the following videos: Dependency injection -------------------- -Dependency Injection sounds pretty complicated but it just means: Don't put new dependencies in your constructor or methods but pass them in. So this: +Dependency Injection sounds pretty complicated but it just means: Don't put +new dependencies in your constructor or methods but pass them in. So this: .. code-block:: php @@ -54,12 +57,21 @@ would turn into this by using Dependency Injection: Using a container ----------------- -Passing dependencies into the constructor rather than instantiating them in the constructor has the following drawback: Every line in the source code where **new AuthorMapper** is being used has to be changed, once a new constructor argument is being added to it. +.. note:: Please do use automatic dependency injection (see below). For most +apps there is no need to register services manually. -The solution for this particular problem is to limit the **new AuthorMapper** to one file, the container. The container contains all the factories for creating these objects and is configured in :file:`lib/AppInfo/Application.php`. +Passing dependencies into the constructor rather than instantiating them in the +constructor has the following drawback: Every line in the source code where +**new AuthorMapper** is being used has to be changed, once a new constructor +argument is being added to it. + +The solution for this particular problem is to limit the **new AuthorMapper** to +one file, the container. The container contains all the factories for creating +these objects and is configured in :file:`lib/AppInfo/Application.php`. -To add the app's classes simply open the :file:`lib/AppInfo/Application.php` and use the **registerService** method on the container object: +To add the app's classes simply open the :file:`lib/AppInfo/Application.php` and +use the **registerService** method on the container object: .. code-block:: php