Centralize configure-able factory classes
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {DependencyKey, DependencyRequirement, PropertyDependency} from '../types'
|
||||
import { Collection } from '../../util'
|
||||
import {DependencyKey, DependencyRequirement, Instantiable, PropertyDependency} from '../types'
|
||||
import {Collection, logIfDebugging} from '../../util'
|
||||
import {getPropertyInjectionMetadata} from '../decorator/getPropertyInjectionMetadata'
|
||||
|
||||
/**
|
||||
* Abstract base class for dependency container factories.
|
||||
@@ -42,6 +43,22 @@ export abstract class AbstractFactory<T> {
|
||||
*/
|
||||
abstract getInjectedProperties(): Collection<PropertyDependency>
|
||||
|
||||
/** Helper method that returns all `@Inject()`'ed properties for a token and its prototypical ancestors. */
|
||||
protected getInjectedPropertiesForPrototypeChain(token: Instantiable<any>): Collection<PropertyDependency> {
|
||||
const meta = new Collection<PropertyDependency>()
|
||||
|
||||
do {
|
||||
const loadedMeta = getPropertyInjectionMetadata(token)
|
||||
if ( loadedMeta ) {
|
||||
meta.concat(loadedMeta)
|
||||
}
|
||||
token = Object.getPrototypeOf(token)
|
||||
logIfDebugging('extollo.di.injection', 'next currentToken:', token)
|
||||
} while (token !== Function.prototype && token !== Object.prototype)
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a human-readable name of the token this factory produces.
|
||||
* This is meant for debugging output only.
|
||||
|
||||
Reference in New Issue
Block a user