mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
feat(core): expose each option to get and resolve methods
This commit is contained in:
@@ -4,12 +4,13 @@ import {
|
||||
DynamicModule,
|
||||
ExistingProvider,
|
||||
FactoryProvider,
|
||||
GetOrResolveOptions,
|
||||
Injectable,
|
||||
InjectionToken,
|
||||
NestModule,
|
||||
Provider,
|
||||
ValueProvider,
|
||||
Type,
|
||||
ValueProvider,
|
||||
} from '@nestjs/common/interfaces';
|
||||
import { randomStringGenerator } from '@nestjs/common/utils/random-string-generator.util';
|
||||
import {
|
||||
@@ -520,19 +521,27 @@ export class Module {
|
||||
|
||||
public get<TInput = any, TResult = TInput>(
|
||||
typeOrToken: Type<TInput> | string | symbol,
|
||||
options: { strict: boolean } = { strict: true },
|
||||
): TResult {
|
||||
options: GetOrResolveOptions = { strict: true },
|
||||
): TResult | Array<TResult> {
|
||||
return !(options && options.strict)
|
||||
? this.find<TInput, TResult>(typeOrToken)
|
||||
: this.find<TInput, TResult>(typeOrToken, self);
|
||||
? this.find<TInput, TResult>(typeOrToken, options)
|
||||
: this.find<TInput, TResult>(typeOrToken, {
|
||||
moduleId: self.id,
|
||||
each: options.each,
|
||||
});
|
||||
}
|
||||
|
||||
public resolve<TInput = any, TResult = TInput>(
|
||||
typeOrToken: Type<TInput> | string | symbol,
|
||||
contextId = createContextId(),
|
||||
options: { strict: boolean } = { strict: true },
|
||||
): Promise<TResult> {
|
||||
return this.resolvePerContext(typeOrToken, self, contextId, options);
|
||||
options: GetOrResolveOptions = { strict: true },
|
||||
): Promise<TResult | Array<TResult>> {
|
||||
return this.resolvePerContext<TInput, TResult>(
|
||||
typeOrToken,
|
||||
self,
|
||||
contextId,
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
public async create<T = any>(type: Type<T>): Promise<T> {
|
||||
|
||||
Reference in New Issue
Block a user