-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathdependency_injection_examples.services.yml
40 lines (35 loc) · 1.41 KB
/
dependency_injection_examples.services.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
services:
# Very basic example of a service that we can use.
awesome_markup_creator:
class: \Drupal\dependency_injection_examples\AwesomeMarkupCreator
# Impractical example to illustrate what arguments are.
my_service_with_arguments:
class: \Drupal\dependency_injection_examples\ServiceWithArguments
arguments:
- 'hello'
- 17
# Example to illustrate that the same class can be used with different arguments.
my_other_service_with_arguments:
class: \Drupal\dependency_injection_examples\ServiceWithArguments
arguments:
- 'another example'
- 'with different arguments'
# Practical example of injecting other services as dependencies into our new
# service using arguments.
# AKA: "Wiring" services, specifically "Manual Wiring".
my_service_with_wired_services:
class: \Drupal\dependency_injection_examples\ServiceWithWiredServices
arguments:
- '@awesome_markup_creator'
- '@my_service_with_arguments'
- '@messenger'
- '@logger.factory'
# Example of injecting dependencies using a Setter on the service class.
my_service_with_setter_injection:
class: \Drupal\dependency_injection_examples\SetterInjectionExample
arguments:
- '@my_other_service_with_arguments'
calls:
- ['setAwesomeMarkupCreator', ['@awesome_markup_creator'] ]
- ['setLogger', ['@logger.factory'] ]
- ['setMessenger', ['@messenger'] ]