-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac02007
commit f440e0b
Showing
9 changed files
with
108 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- 版本 | ||
- [4.6](4.6/) | ||
- [5.0](5.0/) | ||
- [5.0](5.0/) | ||
- [6.x](6/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- 版本 | ||
- [4.6](4.6/) | ||
- [5.0](5.0/) | ||
- [5.0](5.0/) | ||
- [6.x](6/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- 版本 | ||
- [4.6](4.6/) | ||
- [5.0](5.0/) | ||
- [5.0](5.0/) | ||
- [6.x](6/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,37 @@ | ||
- [介绍](6/introduction) | ||
|
||
- 概述 | ||
- [第一步](5.0/firststeps) | ||
- [控制器](5.0/controllers) | ||
- [提供者](5.0/providers) | ||
- [模块](5.0/modules) | ||
- [中间件](5.0/middlewares) | ||
- [异常过滤器](5.0/exceptionfilters) | ||
- [管道](5.0/pipes) | ||
- [守卫](5.0/guards) | ||
- [拦截器](5.0/interceptors) | ||
- [自定义装饰器](5.0/customdecorators) | ||
- [关于翻译](5.0/about) | ||
- [第一步](6/firststeps) | ||
- [控制器](6/controllers) | ||
- [提供者](6/providers) | ||
- [模块](6/modules) | ||
- [中间件](6/middlewares) | ||
- [异常过滤器](6/exceptionfilters) | ||
- [管道](6/pipes) | ||
- [守卫](6/guards) | ||
- [拦截器](6/interceptors) | ||
- [自定义装饰器](6/customdecorators) | ||
- [关于翻译](6/about) | ||
|
||
- [基本原理](6/fundamentals) | ||
|
||
- [基本原理](5.0/fundamentals) | ||
- [技术](6/techniques) | ||
|
||
- [技术](5.0/techniques) | ||
- [GraphQL](6/graphql) | ||
|
||
- [GraphQL](5.0/graphql) | ||
- [WEBSOCKETS](6/websockets) | ||
|
||
- [WEBSOCKETS](5.0/websockets) | ||
- [微服务](6/microservices) | ||
|
||
- [微服务](5.0/microservices) | ||
- [应用上下文](6/applicationcontext) | ||
|
||
- [执行上下文](5.0/executioncontext) | ||
- [秘籍](6/recipes) | ||
|
||
- [秘籍](5.0/recipes) | ||
- [CLI](6/cli) | ||
|
||
- [CLI](5.0/cli) | ||
- [FAQ](6/faq) | ||
|
||
- [FAQ](5.0/faq) | ||
- [迁移指南](6/migrationguide) | ||
|
||
- [迁移指南](5.0/migrationguide) | ||
- [谁在使用 Nest](6/discover) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# 应用上下文 | ||
|
||
有几种安装 Nest 应用程序的方法。您可以创建一个 Web 应用程序,微服务或只是一个 Nest **执行上下文** 。 Nest 上下文是 Nest 容器的一个包装,它包含所有实例化的类。我们可以直接使用应用程序对象从任何导入的模块中获取现有实例。由于这一点,您可以充分利用 Nest 框架的优势,包括 **CRON** 任务,甚至可以在其上构建 **CLI** 。 | ||
|
||
为了创建一个 Nest 应用程序上下文,我们使用下面的语法: | ||
|
||
```typescript | ||
async function bootstrap() { | ||
const app = await NestFactory.createApplicationContext(ApplicationModule); | ||
// logic... | ||
} | ||
bootstrap(); | ||
``` | ||
|
||
之后,Nest 允许您选择在 Nest 应用程序中注册的任何实例。假设我们在 `TasksModule` 中有一个 `TasksController` 。这个类提供了一组我们想从 CRON 任务中调用可用的方法。 | ||
|
||
```typescript | ||
const app = await NestFactory.create(ApplicationModule); | ||
const tasksController = app.get(TasksController); | ||
``` | ||
|
||
就是这样。要获取 `TasksController` 实例,我们必须使用 `get()` 方法。我们不必遍历整个模块树,`get()` 方法就像 **查询** 一样,自动在每个注册模块中搜索实例。但是,如果您更喜欢严格的上下文检查,则可以使用 `strict: true` 选项对象作为 `get()` 方法的第二个参数传递给它。然后,您必须通过所有模块从选定的上下文中选取特定的实例。 | ||
|
||
```typescript | ||
const app = await NestFactory.create(ApplicationModule); | ||
const tasksController = app.select(TasksModule).get(TasksController, { strict: true }); | ||
``` | ||
|
||
| | | | ||
| :------------ | :----------------------------------------------------------- | | ||
| `get()` | 检索应用程序上下文中可用的控制器或提供者(包括看守器,过滤器等)的实例。 | | ||
| `select()` | 浏览模块树,例如,从所选模块中提取特定实例(与启用严格模式一起使用)。 | | ||
|
||
?> 默认情况下,根模块处于选中状态。要选择任何其他模块,您需要遍历整个模块树(逐步)。 | ||
|
||
### 译者署名 | ||
|
||
| 用户名 | 头像 | 职能 | 签名 | | ||
|---|---|---|---| | ||
| [@zuohuadong](https://github.com/zuohuadong) | <img class="avatar-66 rm-style" src="https://wx3.sinaimg.cn/large/006fVPCvly1fmpnlt8sefj302d02s742.jpg"> | 翻译 | 专注于 caddy 和 nest,[@zuohuadong](https://github.com/zuohuadong/) at Github | | ||
| [@Drixn](https://drixn.com/) | <img class="avatar-66 rm-style" src="https://cdn.drixn.com/img/src/avatar1.png"> | 翻译 | 专注于 nginx 和 C++,[@Drixn](https://drixn.com/) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# 介绍 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- 版本 | ||
- [4.6](4.6/) | ||
- [5.0](5.0/) | ||
- [5.0](5.0/) | ||
- [6.x](6/) |