|
|
|
@ -66,13 +66,7 @@ class Container {
|
|
|
|
|
* @returns {module:flitter-di/src/Service~Service|undefined} - the service instance or service container proxy
|
|
|
|
|
*/
|
|
|
|
|
service(service = false) {
|
|
|
|
|
if ( service === false ) {
|
|
|
|
|
return new Proxy({}, {
|
|
|
|
|
get: (obj, prop) => {
|
|
|
|
|
return this.service(prop)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
if ( service === false ) return this.proxy()
|
|
|
|
|
|
|
|
|
|
if ( !this.definitions[service] ) {
|
|
|
|
|
throw new Error('No such service registered with this container: '+service)
|
|
|
|
@ -95,6 +89,14 @@ class Container {
|
|
|
|
|
return this.instances[service]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
proxy() {
|
|
|
|
|
return new Proxy({}, {
|
|
|
|
|
get: (what, name) => {
|
|
|
|
|
return this.service(name)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register a class definition as a service. When requested, the service
|
|
|
|
|
* for this class will be created from the class' instance.
|
|
|
|
|