Skip to content

GetOrResolveOptions

reference
1 min readUpdated

Kind: Interface

Source: packages/common/interfaces/nest-application-context.interface.ts

Part of: Common

GetOrResolveOptions configures how a Nest application context looks up or resolves providers. Use strict to control whether resolution is limited to the current module context, and each to request all matching provider instances instead of a single result.

Properties

PropertyType
strictboolean
eachboolean

Diagram

mermaid
graph LR
  A[Application Context] --> B[GetOrResolveOptions]
  B --> C[strict: boolean]
  B --> D[each: boolean]
  C --> E[Limit lookup to current module context]
  D --> F[Return one or all matching providers]

Usage

ts
import { NestFactory } from '@nestjs/core';
import { GetOrResolveOptions } from '@nestjs/common';

const options: GetOrResolveOptions = {
  strict: false,
  each: true,
};

const app = await NestFactory.createApplicationContext(AppModule);

// Search across module boundaries and return every matching provider.
const handlers = app.get(MyHandlerToken, options);

handlers.forEach((handler) => handler.handle());

AI Coding Instructions

  • Set strict: true when a provider must be resolved only from the current module context.
  • Use strict: false for cross-module provider lookup when providers are exported through imported modules.
  • Set each: true only when multiple providers may share the requested token; handle the returned collection accordingly.
  • Keep provider tokens and expected return types aligned, especially when using custom injection tokens.
  • Prefer explicit options when lookup behavior is important to avoid unintended module-boundary resolution.

Used by

2 references from 2 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (2)

  • AbstractInstanceResolverpackages/core/injector/abstract-instance-resolver.ts:12
  • NestApplicationContextpackages/core/nest-application-context.ts:40

Was this page helpful?

Download as PDF
GetOrResolveOptions — NestJS head-to-head