@@ -111,9 +111,8 @@ Optionally, you can specify a connection name in the decorator parameters.
111
111
112
112
### @OrmRepository
113
113
114
- Injects ` Repository ` of some Entity.
115
-
116
- If you want to inject custom Repository (class decorated with ` @EntityRepository ` decorator), use ` OrmCustomRepository ` instead.
114
+ Injects ` Repository ` , ` MongoRepository ` , ` TreeRepository ` or custom repository of some Entity.
115
+ Be aware that the property or param decorated with ` @OrmRepository ` has to be annotated with repository type!
117
116
118
117
Example using property injection:
119
118
@@ -143,16 +142,27 @@ import "../entity/Post";
143
142
@Service ()
144
143
export class PostRepository {
145
144
146
- constructor (@OrmRepository (Post ) private repository : Repository <Post >) {
147
- }
145
+ constructor (
146
+ @OrmRepository (Post )
147
+ private repository : Repository <Post >
148
+ ) {}
148
149
149
150
}
150
151
```
151
- Optionally, you can specify a connection name in the decorator parameters.
152
+ Optionally, you can specify a connection name in the decorator parameters:
152
153
153
- ### @OrmCustomRepository
154
+ ``` ts
155
+ @Service ()
156
+ export class PostRepository {
157
+
158
+ @OrmRepository (Post , " custom-con-name" )
159
+ private repository: Repository <Post >;
160
+
161
+ }
162
+ ```
154
163
155
- Injects custom ` Repository ` of some Entity. Be aware that you have to create the class which extends the generic ` Repository<T> ` and decorate it with ` EntityRepository<T> ` decorator.
164
+ You can also inject custom ` Repository ` of some Entity.
165
+ Be aware that you have to create the class which extends the generic ` Repository<T> ` and decorate it with ` EntityRepository<T> ` decorator.
156
166
157
167
Example using constructor injection:
158
168
@@ -178,9 +188,9 @@ export class PostService {
178
188
179
189
// using constructor injection
180
190
constructor (
181
- @OrmCustomRepository ( UserRepository )
182
- private readonly userRepository : UserRepository
183
- )
191
+ @OrmRepository ( )
192
+ private readonly userRepository : UserRepository ,
193
+ ) {}
184
194
185
195
public userExist(user : User ): boolean {
186
196
return this .userRepository .findByEmail (user .email ) ? true : false ;
@@ -191,86 +201,16 @@ export class PostService {
191
201
192
202
Optionally, you can specify a connection name in the decorator parameters.
193
203
194
- ### @OrmTreeRepository
195
-
196
- Injects ` TreeRepository ` of some Entity.
197
-
198
- Example using property injection:
199
-
200
- ``` typescript
201
- import {Service } from " typedi" ;
202
- import {TreeRepository } from " typeorm" ;
203
- import {OrmTreeRepository } from " typeorm-typedi-extensions" ;
204
- import " ../entity/Post" ;
205
-
206
- @Service ()
207
- export class PostRepository {
208
-
209
- @OrmTreeRepository (Post )
210
- private repository: TreeRepository <Post >;
211
-
212
- }
213
- ```
214
-
215
- Example using constructor injection:
216
-
217
- ``` typescript
218
- import {Service } from " typedi" ;
219
- import {TreeRepository } from " typeorm" ;
220
- import {OrmTreeRepository } from " typeorm-typedi-extensions" ;
221
- import " ../entity/Post" ;
222
-
223
- @Service ()
224
- export class PostRepository {
225
-
226
- constructor (@OrmTreeRepository (Post ) private repository : TreeRepository <Post >) {
227
- }
228
-
229
- }
230
- ```
231
-
232
- Optionally, you can specify a connection name in the decorator parameters.
233
-
234
- ### @OrmSpecificRepository
235
-
236
- Injects ` SpecificRepository ` of some Entity.
237
-
238
- Example using property injection:
239
-
240
- ``` typescript
241
- import {Service } from " typedi" ;
242
- import {SpecificRepository } from " typeorm" ;
243
- import {OrmSpecificRepository } from " typeorm-typedi-extensions" ;
244
- import " ../entity/Post" ;
245
-
246
- @Service ()
247
- export class PostRepository {
248
-
249
- @OrmSpecificRepository (Post )
250
- private repository: SpecificRepository <Post >;
251
-
252
- }
253
- ```
254
-
255
- Example using constructor injection:
256
-
257
- ``` typescript
258
- import {Service } from " typedi" ;
259
- import {SpecificRepository } from " typeorm" ;
260
- import {OrmSpecificRepository } from " typeorm-typedi-extensions" ;
261
- import " ../entity/Post" ;
262
-
204
+ ``` ts
263
205
@Service ()
264
- export class PostRepository {
206
+ export class PostService {
265
207
266
- constructor (@ OrmSpecificRepository ( Post ) private repository : SpecificRepository < Post >) {
267
- }
208
+ @ OrmRepository ( " custom-con-name " )
209
+ private userRepository : UserRepository ;
268
210
269
211
}
270
212
```
271
213
272
- Optionally, you can specify a connection name in the decorator parameters.
273
-
274
214
## Samples
275
215
276
216
Take a look on samples in [ ./sample] ( sample ) for examples of usages.
0 commit comments