@@ -16,7 +16,7 @@ import SingletonCache from './fixtures/decators/SingletonCache';
1616import { PrototypeUtil , QualifierUtil } from '..' ;
1717import QualifierCacheService from './fixtures/decators/QualifierCacheService' ;
1818import { FOO_ATTRIBUTE , FooLogger } from './fixtures/decators/FooLogger' ;
19- import { ConstructorObject } from './fixtures/decators/ConstructorObject' ;
19+ import { ConstructorObject , ConstructorQualifierObject } from './fixtures/decators/ConstructorObject' ;
2020import {
2121 ChildDynamicMultiInstanceProto ,
2222 ChildSingletonProto ,
@@ -90,8 +90,9 @@ describe('test/decorator.test.ts', () => {
9090 assert . deepStrictEqual ( injectConstructors , [
9191 { refIndex : 0 , refName : 'xCache' , objName : 'fooCache' } ,
9292 { refIndex : 1 , refName : 'cache' , objName : 'cache' } ,
93- { refIndex : 2 , refName : 'optional1' , objName : 'optional1' , optional : true } ,
94- { refIndex : 3 , refName : 'optional2' , objName : 'optional2' , optional : true } ,
93+ { refIndex : 2 , refName : 'otherCache' , objName : 'cacheService' } ,
94+ { refIndex : 3 , refName : 'optional1' , objName : 'optional1' , optional : true } ,
95+ { refIndex : 4 , refName : 'optional2' , objName : 'optional2' , optional : true } ,
9596 ] ) ;
9697 } ) ;
9798 } ) ;
@@ -107,6 +108,23 @@ describe('test/decorator.test.ts', () => {
107108 QualifierUtil . getProperQualifier ( QualifierCacheService , property , InitTypeQualifierAttribute ) === ObjectInitType . SINGLETON ,
108109 ) ;
109110 } ) ;
111+
112+ it ( 'should set default initType in inject' , ( ) => {
113+ const properties = [
114+ { property : 'interfaceService' , expected : undefined } ,
115+ { property : 'testContextService' , expected : ObjectInitType . CONTEXT } ,
116+ { property : 'testSingletonService' , expected : ObjectInitType . SINGLETON } ,
117+ { property : 'customNameService' , expected : undefined } ,
118+ { property : 'customQualifierService1' , expected : ObjectInitType . CONTEXT } ,
119+ { property : 'customQualifierService2' , expected : ObjectInitType . CONTEXT } ,
120+ ] ;
121+
122+ for ( const { property, expected } of properties ) {
123+ const qualifier = QualifierUtil . getProperQualifier ( QualifierCacheService , property , InitTypeQualifierAttribute ) ;
124+ assert . strictEqual ( qualifier , expected , `expect initType for ${ property } to be ${ expected } ` ) ;
125+ }
126+ } ) ;
127+
110128 it ( 'should work use Symbol.for' , ( ) => {
111129 assert ( PrototypeUtil . isEggPrototype ( QualifierCacheService ) ) ;
112130 const property = 'cache' ;
@@ -117,6 +135,7 @@ describe('test/decorator.test.ts', () => {
117135 QualifierUtil . getProperQualifier ( QualifierCacheService , property , Symbol . for ( 'Qualifier.InitType' ) ) === ObjectInitType . SINGLETON ,
118136 ) ;
119137 } ) ;
138+
120139 it ( 'constructor should work' , ( ) => {
121140 const constructorQualifiers = QualifierUtil . getProperQualifiers ( ConstructorObject , 'xCache' ) ;
122141 const constructorQualifiers2 = QualifierUtil . getProperQualifiers ( ConstructorObject , 'cache' ) ;
@@ -126,6 +145,22 @@ describe('test/decorator.test.ts', () => {
126145 ] ) ;
127146 assert . deepStrictEqual ( constructorQualifiers2 , [ ] ) ;
128147 } ) ;
148+
149+ it ( 'should set default initType in constructor inject' , ( ) => {
150+ const properties = [
151+ { property : 'xCache' , expected : undefined } ,
152+ { property : 'cache' , expected : ObjectInitType . SINGLETON } ,
153+ { property : 'ContextCache' , expected : ObjectInitType . CONTEXT } ,
154+ { property : 'customNameCache' , expected : undefined } ,
155+ { property : 'customQualifierCache1' , expected : ObjectInitType . CONTEXT } ,
156+ { property : 'customQualifierCache2' , expected : ObjectInitType . CONTEXT } ,
157+ ] ;
158+
159+ for ( const { property, expected } of properties ) {
160+ const qualifier = QualifierUtil . getProperQualifier ( ConstructorQualifierObject , property , InitTypeQualifierAttribute ) ;
161+ assert . strictEqual ( qualifier , expected , `expect initType for ${ property } to be ${ expected } ` ) ;
162+ }
163+ } ) ;
129164 } ) ;
130165
131166 describe ( 'MultiInstanceProto' , ( ) => {
0 commit comments