Skip to content
This repository was archived by the owner on Feb 17, 2022. It is now read-only.

7.x 2.x service container

Andy Truong edited this page Jan 16, 2014 · 9 revisions

Service Container [7.x-2.x]

Dependency help our code clean, testable…

The Service Container in this module is built on Pimple.

If we defined

# /at_base/tests/atest_base/config/services.yml
services:
  atest_base.service_1:
    class: 'Drupal\atest_base\Service_1'
  atest_base.service_2:
    class: 'Drupal\atest_base\Service_2'
    arguments: ['@atest_base.service_1']

We can get instance of service_2:

$service_2 = at_container('atest_base.service_2');

Get all services tagged with 'cache.warmer':

$name_of_services = at_container('container')->find('cache.warmer', $return = 'service_name');
$obj_of_servcies = at_container('container')->find('cache.warmer', $return = 'service');

Clone this wiki locally