Fix DI bugs; implement general logging service
This commit is contained in:
@@ -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}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user