mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
handle another circular dependency scenario in DI
This commit is contained in:
parent
66be5cd907
commit
5776439ac8
|
@ -96,9 +96,14 @@ class ContainerClass {
|
||||||
} else {
|
} else {
|
||||||
const paramTypes = (Reflect.getMetadata('design:paramtypes', type) ??
|
const paramTypes = (Reflect.getMetadata('design:paramtypes', type) ??
|
||||||
[]) as Constructable[];
|
[]) as Constructable[];
|
||||||
const dependencies = paramTypes.map(<P>(paramType: Constructable<P>) =>
|
const dependencies = paramTypes.map(<P>(paramType: Constructable<P>, index: number) => {
|
||||||
this.get(paramType),
|
if (paramType === undefined) {
|
||||||
|
throw new DIError(
|
||||||
|
`Circular dependency detected in ${type.name} at index ${index}.\n${resolutionStack.map((t) => t.name).join(' -> ')}\n`,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
return this.get(paramType);
|
||||||
|
});
|
||||||
// Create new instance with resolved dependencies
|
// Create new instance with resolved dependencies
|
||||||
instance = new (type as Constructable)(...dependencies) as T;
|
instance = new (type as Constructable)(...dependencies) as T;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue