Add generic session interfaces; memory session; factories; kernel

This commit is contained in:
garrettmills
2020-07-24 09:53:30 -05:00
parent b9f2f844f3
commit 878de025d8
11 changed files with 184 additions and 6 deletions

View File

@@ -146,7 +146,7 @@ class Container {
make(target: DependencyKey, ...parameters: any[]) {
if ( this.has_key(target) )
return this.resolve_and_create(target, ...parameters)
else if ( typeof target !== 'string' )
else if ( typeof target !== 'string' && isInstantiable(target) )
return this.produce_factory(new Factory(target), parameters)
else
throw new TypeError(`Invalid or unknown make target: ${target}`)

View File

@@ -1,4 +1,5 @@
import Instantiable from './Instantiable.ts'
import {StaticClass} from './StaticClass.ts'
const DEPENDENCY_KEYS_METADATA_KEY = 'daton:di:dependencyKeys.ts'
type DependencyKey = Instantiable<any> | string
type DependencyKey = Instantiable<any> | StaticClass<any> | string
export { DependencyKey, DEPENDENCY_KEYS_METADATA_KEY }

View File

@@ -0,0 +1,5 @@
export type StaticClass<T> = Function & {prototype: T}
export function isStaticClass<T>(something: any): something is StaticClass<T> {
return typeof something === 'function' && typeof something.prototype !== 'undefined'
}