UNPKG

@inversifyjs/core

Version:

InversifyJs core package

28 lines 1.4 kB
import { isPromise } from '@inversifyjs/common'; import { resolvePostConstruct } from './resolvePostConstruct.js'; function resolveAllPostConstructMethods(instance, binding, postConstructMethodNames) { if (postConstructMethodNames.size === 0) { return instance; } let result = instance; for (const methodName of postConstructMethodNames) { if (isPromise(result)) { result = result.then((resolvedInstance) => resolvePostConstruct(resolvedInstance, binding, methodName)); } else { result = resolvePostConstruct(result, binding, methodName); } } return result; } export function resolveInstanceBindingNodeFromConstructorParams(setInstanceProperties) { return (constructorValues, params, node) => { const instance = new node.binding.implementationType(...constructorValues); const propertiesAssignmentResult = setInstanceProperties(params, instance, node); if (isPromise(propertiesAssignmentResult)) { return propertiesAssignmentResult.then(() => resolveAllPostConstructMethods(instance, node.binding, node.classMetadata.lifecycle.postConstructMethodNames)); } return resolveAllPostConstructMethods(instance, node.binding, node.classMetadata.lifecycle.postConstructMethodNames); }; } //# sourceMappingURL=resolveInstanceBindingNodeFromConstructorParams.js.map