Skip to content

Commit d81e6d7

Browse files
authored
Merge pull request ascoders#320 from rmlzy/patch-1
Update 20.精读《Nestjs》文档.md
2 parents 3e299d8 + 0a090cf commit d81e6d7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

前沿技术/20.精读《Nestjs》文档.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Nestjs 是我见过的,将 Typescript 与 Nodejs Framework 结合的最好的
1414

1515
Nestjs 不是一个新轮子,它是基于 Express、socket.io 封装的 nodejs 后端开发框架,对 Typescript 开发者提供类型支持,也能优雅降级供 Js 使用,拥有诸多特性,像中间件等就不展开了,本文重点列举其亮点特性。
1616

17-
## 2.1 Modules, Controllers, Components
17+
## 2.1 Modules, Controllers, Providers
1818

19-
Nestjs 开发围绕着这三个单词,Modules 是最大粒度的拆分,表示应用或者模块。Controllers 是传统意义的控制器,一个 Module 拥有多个 Controller。Components 一般用于做 Services,比如将数据库 CRUD 封装在 Services 中,每个 Service 就是一个 Component
19+
Nestjs 开发围绕着这三个单词,Modules 是最大粒度的拆分,表示应用或者模块。Controllers 是传统意义的控制器,一个 Module 拥有多个 Controller。Providers 一般用于做 Services,比如将数据库 CRUD 封装在 Services 中,每个 Service 就是一个 Provider
2020

2121
## 2.2 装饰器路由
2222

@@ -50,7 +50,7 @@ export class UsersController {
5050

5151
## 2.3 模块间依赖注入
5252

53-
Modules, Controllers, Components 之间通过依赖注入相互关联,它们通过同名的 `@Module` `@Controller` `@Component` 装饰器申明,如:
53+
Modules, Controllers, Providers 之间通过依赖注入相互关联,它们通过同名的 `@Module` `@Controller` `@Injectable` 装饰器申明,如:
5454

5555
```typescript
5656
@Controller()
@@ -61,7 +61,7 @@ export class UsersController {
6161
```
6262

6363
```typescript
64-
@Component()
64+
@Injectable()
6565
export class UsersService {
6666
getAllUsers() {
6767
return []
@@ -72,12 +72,12 @@ export class UsersService {
7272
```typescript
7373
@Module({
7474
controllers: [ UsersController ],
75-
components: [ UsersService ],
75+
providers: [ UsersService ],
7676
})
7777
export class ApplicationModule {}
7878
```
7979

80-
`ApplicationModule` 申明其内部 Controllers 与 Components 后,就可以在 Controllers 中注入 Components 了:
80+
`ApplicationModule` 申明其内部 Controllers 与 Providers 后,就可以在 Controllers 中注入 Providers 了:
8181

8282
```typescript
8383
@Controller()

0 commit comments

Comments
 (0)