UNPKG

ayanami

Version:
17 lines (16 loc) 709 B
import { InjectableFactory } from '@asuka/di'; import { createOrGetInstanceInScope, createScopeWithRequest } from './utils'; import { SameScope } from './same-scope-decorator'; export { SameScope, createScopeWithRequest }; export const TransientScope = Symbol('scope:transient'); export const SingletonScope = Symbol('scope:singleton'); export function getInstanceWithScope(constructor, scope = SingletonScope) { switch (scope) { case SingletonScope: return InjectableFactory.getInstance(constructor); case TransientScope: return InjectableFactory.initialize(constructor); default: return createOrGetInstanceInScope(constructor, scope); } }