Fix DI bugs; implement general logging service

This commit is contained in:
garrettmills
2020-06-17 09:48:01 -05:00
parent 6c4696227b
commit eddb4f1fbe
13 changed files with 258 additions and 5 deletions

View File

@@ -133,11 +133,14 @@ class Container {
return factory.produce(construction_args, params.reverse().all())
}
make<T>(target: Instantiable<T>|DependencyKey, ...parameters: any[]): T {
if ( isInstantiable(target) )
make(target: DependencyKey, ...parameters: any[]) {
if ( this.has_key(target) ) {
return this.resolve_and_create(target, ...parameters)
}
else if ( typeof target !== 'string' )
return this.produce_factory(new Factory(target), parameters)
else
return this.resolve_and_create(target, ...parameters)
throw new TypeError(`Invalid or unknown make target: ${target}`)
}
}

View File

@@ -1,11 +1,16 @@
import { container } from '../global.ts'
import { isInstantiable } from '../type/Instantiable.ts'
import { Injectable } from './Injection.ts'
const injectable = Injectable()
const Service = (name?: string): ClassDecorator => {
return (target) => {
if ( isInstantiable(target) ) {
if ( name ) container.register_named(name, target)
else container.register(target)
injectable(target)
}
}
}