Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kurten authored and wang-ran committed Dec 4, 2018
1 parent 050e2fc commit 8f59981
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/context/src/factory/common/ManagedResolverFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ export class ManagedResolverFactory {
// after properties set then do init
definition.creator.doInit(inst);

if (definition.isSingletonScope()) {
if (definition.isSingletonScope() && definition.id) {
this.singletonCache.set(definition.id, inst);
}

Expand Down Expand Up @@ -487,7 +487,7 @@ export class ManagedResolverFactory {
// after properties set then do init
await definition.creator.doInitAsync(inst);

if (definition.isSingletonScope()) {
if (definition.isSingletonScope() && definition.id) {
this.singletonCache.set(definition.id, inst);
}

Expand Down
13 changes: 13 additions & 0 deletions packages/context/test/fixtures/app/lib/ctor/obj7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const assert = require('assert');

module.exports = class Obj7 {
constructor(options) {
assert(options.hello, 'hello is null')
console.log(options);
this.options = options;
}

getHello() {
return this.options.hello;
}
}
22 changes: 22 additions & 0 deletions packages/context/test/fixtures/app/resources/construction.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@
<object id="ctor:obj3" path="obj3" direct="true">
</object>

<object id="ctor:obj7" path="obj7">
<constructor-arg>
<object>
<property name="hello" value="hello" />
<property name="reff">
<ref object="ctor:obj2"></ref>
</property>
</object>
</constructor-arg>
</object>

<object id="ctor:obj8" path="obj7">
<constructor-arg>
<object>
<property name="hello" value="hello8" />
<property name="reff">
<ref object="ctor:obj2"></ref>
</property>
</object>
</constructor-arg>
</object>

<object id="ctor:async" path="async" async="true" construct-method="getInstance">
</object>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,11 @@ describe('/test/unit/factory/xml/XmlApplicationContext', () => {
expect(obj62).deep.eq(obj63);
expect(obj6).deep.eq(obj63);
});
it('context constructor-arg object should be ok', () => {
const aa: any = context.get('ctor:obj7');
expect(aa.getHello()).eq('hello');

const aa1: any = context.get('ctor:obj8');
expect(aa1.getHello()).eq('hello8');
});
});

0 comments on commit 8f59981

Please sign in to comment.