You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+15-8Lines changed: 15 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,37 +1,41 @@
1
1
# dot-annotated-services
2
2
3
-
DotKernel component used to create services through [Laminas Service Manager](https://github.com/laminas/laminas-servicemanager) and inject them with dependencies just using method annotations. It can also create services without the need to write factories. Annotation parsing can be cached, to improve performance.
3
+
DotKernel dependency injection service.
4
4
5
5
This package can clean up your code, by getting rid of all the factories you write, sometimes just to inject a dependency or two.
Run the following command in your project directory
23
+
Install `dot-annotated-services` by running the following command in your project directory:
24
24
25
25
composer require dotkernel/dot-annotated-services
26
26
27
27
28
-
After installing, add the `ConfigProvider` class to your configuration aggregate, usually: `config/config.php`
28
+
After installing, register `dot-annotated-services` in your project by adding the below line to your configuration aggregate (usually: `config/config.php`):
29
+
30
+
Dot\AnnotatedServices\ConfigProvider::class,
31
+
29
32
30
33
## Usage
31
34
32
35
### Using the AnnotatedServiceFactory
33
36
34
-
You can register services in the service manager using `AnnotatedServiceFactory` as below:
37
+
You can register services in the service manager using `AnnotatedServiceFactory` as seen in the below example:
38
+
35
39
```php
36
40
return [
37
41
'factories' => [
@@ -40,10 +44,12 @@ return [
40
44
];
41
45
```
42
46
47
+
43
48
### NOTE
44
49
> You can use only the fully qualified class name as the service key
45
50
46
51
The next step is to add the `#[Inject]` attribute to the service constructor with the service FQCNs to inject:
52
+
47
53
```php
48
54
use Dot\AnnotatedServices\Attribute\Inject;
49
55
@@ -64,6 +70,7 @@ The `#[Inject]` attribute is telling `AnnotatedServiceFactory` to inject the ser
64
70
Valid service names should be provided, as registered in the service manager.
65
71
66
72
To inject an array value from the service manager, you can use dot notation as below
73
+
67
74
```php
68
75
use Dot\AnnotatedServices\Attribute\Inject;
69
76
@@ -88,7 +95,7 @@ return [
88
95
];
89
96
```
90
97
91
-
The next step is to add the `#[Entity]`annotation in the repository class.
98
+
The next step is to add the `#[Entity]`attribute in the repository class.
92
99
93
100
The `name` field has to be the fully qualified class name.
0 commit comments