|
1 | 1 | # The `@Inject` decorator
|
2 | 2 |
|
3 |
| -The `@Inject()` decorator is a **property and parameter decorator** used to resolve dependencies on a property of a class or on a constructor parameter. |
4 |
| -By default it infers the type of the property or argument and initializes an instance of the detected type, however this behaviour can be overwritten via |
5 |
| -specifying a custom constructable type, `Token` or named service as the first parameter. |
| 3 | +The `@Inject()` decorator is a **property and parameter decorator** used to resolve dependencies on a property of a class or a constructor parameter. |
| 4 | +By default it infers the type of the property or argument and initializes an instance of the detected type, however, this behavior can be overwritten via |
| 5 | +specifying a custom constructable type, `Token`, or named service as the first parameter. |
6 | 6 |
|
7 | 7 | ## Property injection
|
8 | 8 |
|
9 |
| -This decorator is mandatory on properties where a class instance is desired (aka: without the decorator the property will stay undefined). The type of the |
| 9 | +This decorator is mandatory on properties where a class instance is desired (aka: without the decorator, the property will stay undefined). The type of the |
10 | 10 | property is automatically inferred so there is no need to define the desired value as the decorator parameter.
|
11 | 11 |
|
12 | 12 | ```ts
|
@@ -45,8 +45,8 @@ console.log(instance.withoutDecorator);
|
45 | 45 |
|
46 | 46 | ## Constructor Injection
|
47 | 47 |
|
48 |
| -The `@Inject` decorator is not required in constructor injection, when a class is marked with the `@Service` decorator. TypeDI will automatically infer and |
49 |
| -inject the correct class instances for every constructor argument. However it can be used to overwrite the injected type. |
| 48 | +The `@Inject` decorator is not required in constructor injection when a class is marked with the `@Service` decorator. TypeDI will automatically infer and |
| 49 | +inject the correct class instances for every constructor argument. However, it can be used to overwrite the injected type. |
50 | 50 |
|
51 | 51 | ```ts
|
52 | 52 | import 'reflect-metadata';
|
@@ -85,8 +85,8 @@ instance.withoutDecorator.print();
|
85 | 85 |
|
86 | 86 | ## Explicitly requesting target type
|
87 | 87 |
|
88 |
| -By default TypeDI will try to infer the type of the property and arguments and inject the proper class instance. However this is not always possible. |
89 |
| -(For example when a property type is an interface.) In these cases there are three way to overwrite type of the injected value: |
| 88 | +By default, TypeDI will try to infer the type of property and arguments and inject the proper class instance. When this is possible |
| 89 | +(eg: the property type is an interface) there is three-way to overwrite type of the injected value: |
90 | 90 |
|
91 | 91 | - via `@Inject(() => type)` where `type` is a constructable value (eg: a class definition)
|
92 | 92 | - via `@Inject(myToken)` where `myToken` is an instance of `Token` class
|
|
0 commit comments