# Application context

## Application context

Nest 애플리케이션을 마운트하는 방법에는 여러 가지가 있습니다. 웹앱, 마이크로 서비스 또는 Nest **응용 프로그램 컨텍스트**를 만들 수 있습니다. Nest 컨텍스트는 모든 인스턴스화 된 클래스를 보유하는 Nest 컨테이너 주위의 래퍼입니다. 응용 프로그램 객체를 사용하여 가져온 모듈 내에서 기존 인스턴스를 직접 가져올 수 있습니다. 따라서 **CRON** 작업을 포함하여 어디서나 Nest 프레임 워크를 활용할 수 있으며 그 위에 **CLI**를 구축할 수도 있습니다.

## Getting started

Nest 애플리케이션 컨텍스트를 작성하기 위해 다음 구문을 사용합니다.

```typescript
@@filename()
async function bootstrap() {
  const app = await NestFactory.createApplicationContext(ApplicationModule);
  // application logic...
}
bootstrap();
```

이후 Nest를 사용하면 Nest 애플리케이션에 등록된 모든 인스턴스를 선택할 수 있습니다. 우리가 `TasksModule`에 `TasksService`를 가지고 있다고 상상해 봅시다. 이 클래스는 CRON 작업 내에서 호출하려는 사용 가능한 메소드 세트를 제공합니다.

```typescript
@@filename()
const app = await NestFactory.create(ApplicationModule);
const tasksService = app.get(TasksService);
```

그리고 그것이 전부입니다. `TasksService` 인스턴스를 잡기 위해서는 `get()`메소드를 사용해야 했습니다. 우리는 전체 모듈 트리를 거치지 않아도 되는데, `get()`메소드는 등록된 각 모듈에서 인스턴스를 자동으로 검색하는 **query**와 같은 역할을 합니다. 그러나 엄격한 컨텍스트 검사를 선호하는 경우에는 항상 `get()`메소드의 두 번째 인수로 전달해야하는 `strict: true` 옵션 객체를 사용하여 전환할 수 있습니다. 그런 다음 선택한 컨텍스트에서 특정 인스턴스를 선택하려면 모든 모듈을 거쳐야합니다.

```typescript
@@filename()
const app = await NestFactory.create(ApplicationModule);
const tasksService = app.select(TasksModule).get(TasksService, { strict: true });
```

| `get()`    | 애플리케이션 컨텍스트에서 사용 가능한 컨트롤러 또는 제공자 (가드, 필터 등 포함)의 인스턴스를 검색합니다. |
| ---------- | ------------------------------------------------------------ |
| `select()` | 예를 들어, 모듈 그래프를 탐색하여 선택한 모듈에서 특정 인스턴스를 가져옵니다 (엄격한 모드와 함께 사용). |

> info **힌트** 엄격하지 않은 모드에서는 루트 모듈이 기본적으로 선택됩니다. 다른 모듈을 선택하려면 전체 모듈 트리를 단계별로 수행해야합니다.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jakekwak.gitbook.io/nestjs/application-context/application-context-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
