diff --git a/en/appendices/5-3-migration-guide.rst b/en/appendices/5-3-migration-guide.rst index 183bc3d909..0cc1169cec 100644 --- a/en/appendices/5-3-migration-guide.rst +++ b/en/appendices/5-3-migration-guide.rst @@ -147,6 +147,8 @@ ORM validation to the fields listed in the ``fields`` option. - Added ``TableContainer`` that you can register in your Application::services() to add dependency injection for your Tables. +- ``Cake\ORM\Locator\TableContainer`` was added. By adding this container + delegate to your application, ORM Tables can be injected by the DI container. Routing ------- diff --git a/en/development/dependency-injection.rst b/en/development/dependency-injection.rst index 6fe534eab9..715cff288f 100644 --- a/en/development/dependency-injection.rst +++ b/en/development/dependency-injection.rst @@ -188,6 +188,19 @@ instance, often referred to as a singleton, you can mark a service as 'shared':: $container->addShared(BillingService::class); +Using ORM Tables as Services +---------------------------- + +If you want to have ORM Tables injected as a dependency to a service, you can +add ``TableContainer`` to your applications's service container:: + + // In your Application::services() method. + // Allow your Tables to be dependency injected. + $container->delegate(new \Cake\ORM\Locator\TableContainer()); + +.. versionadded:: 5.3.0 + ``TableContainer`` was added. + Extending Definitions ---------------------