Skip to content

Commit e1b7e8c

Browse files
author
craigparra
committed
1.0.6 / 2021-08-16
================== * Fix autowire bug, pass self to destroyer - @craigparra
1 parent e2c0e0f commit e1b7e8c

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

ApplicationContext.js

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ module.exports = class ApplicationContext {
181181
&& component?.constructor?.name !== 'Singleton'
182182
&& component?.constructor?.name !== 'Prototype') {
183183
component = new Component(
184-
component, component.name,
185-
component.qualifier,
186-
component.scope,
187-
component.properties, component.profiles,
184+
component, component.name,
185+
component.qualifier,
186+
component.scope,
187+
component.properties, component.profiles,
188188
);
189189
component.require = componentArg.require;
190190
}
@@ -285,7 +285,8 @@ module.exports = class ApplicationContext {
285285
const insKeys = Object.keys(instance);
286286
for (let j = 0; j < insKeys.length; j++) {
287287
const property = instance[insKeys[j]];
288-
const autowire = property?.name === 'Autowired' || _.lowerCase(property) === 'autowired';
288+
const autowire = property?.name === 'Autowired'
289+
|| (typeof property === 'string' && _.lowerCase(property)) === 'autowired';
289290
if (autowire) {
290291
// eslint-disable-next-line no-param-reassign
291292
instance[insKeys[j]] = this.get(insKeys[j], undefined, component);
@@ -386,7 +387,7 @@ module.exports = class ApplicationContext {
386387

387388
static registerDestroyer(destroyer) {
388389
if (destroyer){
389-
process.on('exit', destroyer?.bind());
390+
// process.on('exit', destroyer?.bind());
390391
// catches ctrl+c event
391392
process.on('SIGINT', destroyer?.bind());
392393
// catches "kill pid" (for example: nodemon restart)
@@ -405,19 +406,17 @@ module.exports = class ApplicationContext {
405406
if (component.scope === Scopes.SINGLETON) {
406407
let destroyer = null;
407408
if (typeof component.instance.destroy === 'function') {
408-
destroyer = component.instance.destroy;
409+
destroyer = () => component.instance.destroy(component.instance);
409410
} else if (typeof component.destroy === 'string') {
410-
destroyer = component.instance[component.destroy]();
411+
destroyer = () => component.instance[component.destroy](component.instance);
411412
}
412413
ApplicationContext.registerDestroyer(destroyer);
413-
ApplicationContext.registerDestroyer(() => {
414-
logger.verbose(`ApplicationContext (${this.name}) lifecycle completed.`);
415-
});
416-
417414
logger.verbose(`Registering singleton (${component.name}) destroyer`);
418415
}
419416
}
420-
417+
ApplicationContext.registerDestroyer(() => {
418+
logger.verbose(`ApplicationContext (${this.name}) lifecycle completed.`);
419+
});
421420
logger.verbose('Registering singleton destroyers completed');
422421
}
423422

@@ -465,7 +464,7 @@ module.exports = class ApplicationContext {
465464
args = [args];
466465
}
467466
prototype = this.get(
468-
this.components[reference].factory,
467+
this.components[reference].factory,
469468
)[this.components[reference].factoryFunction](...args);
470469
} else if (typeof this.components[reference].wireFactory === 'function') {
471470
let args = targetArgs;

History.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
1.0.6 / 2021-08-16
2+
==================
3+
4+
* Fix autowire bug, pass self to destroyer - @craigparra
5+
16
1.0.5 / 2021-08-16
27
==================
38

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alt-javascript/cdi",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "",
55
"author": "Craig Parravicini",
66
"keywords": [

0 commit comments

Comments
 (0)