koatty_container
Advanced tools
Comparing version 1.6.10 to 1.6.11
@@ -85,3 +85,3 @@ "use strict"; | ||
}; | ||
options.args = options.args.length ? options.args : [this.app]; | ||
options.args = options.args.length ? options.args : []; | ||
// inject options once | ||
@@ -94,6 +94,2 @@ Reflect.defineProperty(target.prototype, "_options", { | ||
}); | ||
const ref = this.getClass(options.type, identifier); | ||
if (!ref) { | ||
this.saveClass(options.type, target, identifier); | ||
} | ||
// define app as getter | ||
@@ -114,11 +110,13 @@ const app = this.app; | ||
(0, AOP_1.injectAOP)(target, target.prototype, this); | ||
const ref = this.getClass(options.type, identifier); | ||
if (!ref) { | ||
this.saveClass(options.type, target, identifier); | ||
} | ||
// instantiation | ||
instance = Reflect.construct(target, options.args); | ||
if (options.scope === "Singleton") { | ||
// instantiation | ||
instance = Reflect.construct(target, options.args); | ||
instance = Object.seal(instance); | ||
} | ||
else { | ||
instance = target; | ||
} | ||
// registration | ||
this.instanceMap.set(target, Object.seal(instance)); | ||
this.instanceMap.set(target, instance); | ||
} | ||
@@ -138,9 +136,9 @@ return instance; | ||
const target = this.getClass(identifier, type); | ||
if (!helper.isClass(target)) { | ||
if (!target) { | ||
return null; | ||
} | ||
// get instance from the Container | ||
const instance = this.reg(target, { scope: args.length > 0 ? "Prototype" : "Singleton", type, args }); | ||
const instance = this.instanceMap.get(target); | ||
// require Prototype instance | ||
if (helper.isClass(instance)) { | ||
if (args.length > 0) { | ||
// instantiation | ||
@@ -177,7 +175,6 @@ return Reflect.construct(target, args); | ||
} | ||
const type = this.getType(target); | ||
// get instance from the Container | ||
const instance = this.reg(target, { scope: args.length > 0 ? "Prototype" : "Singleton", type, args }); | ||
const instance = this.instanceMap.get(target); | ||
// require Prototype instance | ||
if (helper.isClass(instance)) { | ||
if (args.length > 0) { | ||
// instantiation | ||
@@ -184,0 +181,0 @@ return Reflect.construct(target, args); |
@@ -23,3 +23,2 @@ /** | ||
options: any; | ||
context: Context; | ||
use: (fn: Function) => any; | ||
@@ -26,0 +25,0 @@ config: (name: string, type?: string) => any; |
{ | ||
"name": "koatty_container", | ||
"version": "1.6.10", | ||
"version": "1.6.11", | ||
"description": "IOC Container for Koatty.", | ||
@@ -77,2 +77,2 @@ "scripts": { | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1870999
1820