feat(core): expose each option to get and resolve methods

This commit is contained in:
Kamil Myśliwiec
2022-11-05 16:09:47 +01:00
parent beaccf3e1a
commit f4d1a1d978
18 changed files with 320 additions and 175 deletions

View File

@@ -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> {