@@ -17,11 +17,16 @@ constructor injection.
17
17
* [ Contributing] ( #contributing )
18
18
19
19
## Installation
20
-
20
+ Install by ` npm `
21
21
``` sh
22
22
npm install --save tsyringe
23
23
```
24
24
25
+ ** or** install with ` yarn ` (this project is developed using ` yarn ` )
26
+ ``` sh
27
+ yarn install --save tsyringe
28
+ ```
29
+
25
30
Modify your ` tsconfig.json ` to include the following settings
26
31
``` json
27
32
{
@@ -38,7 +43,7 @@ Class decorator factory that allows the class' dependencies to be injected at
38
43
runtime.
39
44
40
45
#### Usage
41
- ``` TypeScript
46
+ ``` typescript
42
47
import {decorators } from " tsyringe" ;
43
48
const {injectable} = decorators ;
44
49
@@ -59,7 +64,7 @@ Class decorator factory that registers the class as a singleton within the
59
64
global container.
60
65
61
66
#### Usage
62
- ``` TypeScript
67
+ ``` typescript
63
68
import {decorators } from " tsyringe" ;
64
69
const {singleton} = decorators ;
65
70
@@ -82,7 +87,7 @@ a parameterless constructor that has dependencies auto-resolved.
82
87
** Note** Resolution is performed using the global container
83
88
84
89
#### Usage
85
- ``` TypeScript
90
+ ``` typescript
86
91
import {decorators } from " tsyringe" ;
87
92
const {autoInjectable} = decorators ;
88
93
@@ -105,7 +110,7 @@ Parameter decorator factory that allows for interface and other non-class
105
110
information to be stored in the constructor's metadata
106
111
107
112
#### Usage
108
- ``` TypeScript
113
+ ``` typescript
109
114
import {decorators } from " tsyringe" ;
110
115
const {injectable, inject} = decorators ;
111
116
@@ -124,11 +129,11 @@ class Foo {
124
129
Since classes have type information at runtime, we can resolve them without any
125
130
extra information.
126
131
127
- ``` TypeScript
132
+ ``` typescript
128
133
// Foo.ts
129
134
export class Foo {}
130
135
```
131
- ``` TypeScript
136
+ ``` typescript
132
137
// Bar.ts
133
138
import {Foo } from " ./Foo" ;
134
139
import {decorators } from " tsyringe" ;
@@ -139,7 +144,7 @@ export class Bar {
139
144
constructor (public myFoo : Foo ) {}
140
145
}
141
146
```
142
- ``` TypeScript
147
+ ``` typescript
143
148
// main.ts
144
149
import {container } from " tsyringe" ;
145
150
import {Bar } from " ./Bar" ;
@@ -152,20 +157,20 @@ const myBar = container.resolve(Bar);
152
157
Interfaces don't have type information at runtime, so we need to decorate them
153
158
with ` @inject(...) ` so the container knows how to resolve them.
154
159
155
- ``` TypeScript
160
+ ``` typescript
156
161
// SuperService.ts
157
162
export interface SuperService {
158
163
// ...
159
164
}
160
165
```
161
- ``` TypeScript
166
+ ``` typescript
162
167
// TestService.ts
163
168
import {SuperService } from " ./SuperService" ;
164
169
export class TestService implements SuperService {
165
170
// ...
166
171
}
167
172
```
168
- ``` TypeScript
173
+ ``` typescript
169
174
// Client.ts
170
175
import {decorators } from " tsyringe" ;
171
176
const {injectable, inject} = decorators ;
@@ -175,7 +180,7 @@ export class Client {
175
180
constructor (@inject (" SuperService" ) private service : SuperService ) {}
176
181
}
177
182
```
178
- ``` TypeScript
183
+ ``` typescript
179
184
// main.ts
180
185
import {Client } from " ./Client" ;
181
186
import {TestService } from " ./TestService" ;
0 commit comments