@@ -166,9 +166,9 @@ private <T> Map<Field, ParamValueLoader> fieldLoaders(Class<T> beanClass) {
166166 Type type = field .getGenericType ();
167167 Annotation [] annotations = field .getAnnotations ();
168168 BeanSpec spec = BeanSpec .of (type , annotations , field .getName (), injector );
169- ParamValueLoader loader = findLoader (spec , type , annotations );
170- boolean loadedByGenie = (loader instanceof ProvidedValueLoader && field . isAnnotationPresent ( Inject . class ) );
171- if (null != loader && !loadedByGenie ) {
169+ ParamValueLoader loader = paramValueLoaderOf (spec , null );
170+ boolean provided = (loader instanceof ProvidedValueLoader );
171+ if (null != loader && !provided ) {
172172 fieldLoaders .put (field , loader );
173173 }
174174 }
@@ -188,24 +188,31 @@ protected ParamValueLoader[] findMethodParamLoaders(Method method) {
188188 for (int i = 0 ; i < sz ; ++i ) {
189189 String name = paramName (i );
190190 BeanSpec spec = BeanSpec .of (types [i ], annotations [i ], name , injector );
191- ParamValueLoader loader = paramRegistry .get ($ .T2 (types [i ], annotations [i ]));
192- if (null == loader ) {
193- if (Result .class .isAssignableFrom (spec .rawType ())) {
194- loader = RESULT_LOADER ;
195- } else if (Exception .class .isAssignableFrom (spec .rawType ())) {
196- loader = EXCEPTION_LOADED ;
197- } else {
198- loader = findLoader (spec , types [i ], annotations [i ]);
199- }
200- // Cannot use spec as the key here because
201- // spec does not compare Scoped annotation
202- paramRegistry .putIfAbsent ($ .T2 (types [i ], annotations [i ]), loader );
203- }
204- loaders [i ] = loader ;
191+ loaders [i ] = paramValueLoaderOf (spec , null );
205192 }
206193 return loaders ;
207194 }
208195
196+ private ParamValueLoader paramValueLoaderOf (BeanSpec spec , String bindName ) {
197+ Class <?> rawType = spec .rawType ();
198+ if (Result .class .isAssignableFrom (rawType )) {
199+ return RESULT_LOADER ;
200+ } else if (Exception .class .isAssignableFrom (rawType )) {
201+ return EXCEPTION_LOADED ;
202+ }
203+ Type type = spec .type ();
204+ Annotation [] annotations = spec .allAnnotations ();
205+ $ .T2 <Type , Annotation []> key = $ .T2 (type , annotations );
206+ ParamValueLoader loader = paramRegistry .get (key );
207+ if (null == loader ) {
208+ loader = findLoader (spec , type , annotations , bindName );
209+ // Cannot use spec as the key here because
210+ // spec does not compare Scoped annotation
211+ paramRegistry .putIfAbsent (key , loader );
212+ }
213+ return loader ;
214+ }
215+
209216 protected abstract ParamValueLoader findContextSpecificLoader (
210217 String bindName ,
211218 Class rawType ,
@@ -225,7 +232,8 @@ protected boolean supportJsonDecorator() {
225232 private ParamValueLoader findLoader (
226233 BeanSpec spec ,
227234 Type type ,
228- Annotation [] annotations
235+ Annotation [] annotations ,
236+ String bindName
229237 ) {
230238 Class rawType = spec .rawType ();
231239 if (provided (spec , injector )) {
@@ -234,7 +242,9 @@ private ParamValueLoader findLoader(
234242 if (null != filter (annotations , NoBind .class )) {
235243 return null ;
236244 }
237- String bindName = bindName (annotations , spec .name ());
245+ if (null == bindName ) {
246+ bindName = bindName (annotations , spec .name ());
247+ }
238248 ParamValueLoader loader = findContextSpecificLoader (bindName , rawType , spec , type , annotations );
239249 return decorate (loader , spec , annotations , supportJsonDecorator ());
240250 }
@@ -351,10 +361,9 @@ public Object create() {
351361 }
352362
353363 private ParamValueLoader findLoader (ParamKey paramKey , Field field ) {
354- BeanSpec spec = BeanSpec .of (field .getGenericType (), field .getDeclaredAnnotations (), App .instance ().injector ());
355- Class fieldType = field .getType ();
364+ BeanSpec spec = BeanSpec .of (field .getGenericType (), field .getDeclaredAnnotations (), injector );
356365 Annotation [] annotations = field .getDeclaredAnnotations ();
357- if (ActProviders . isProvided ( fieldType ) || null != filter ( annotations , Inject . class )) {
366+ if (provided ( spec , injector )) {
358367 return ProvidedValueLoader .get (spec , injector );
359368 }
360369 String name = null ;
@@ -367,11 +376,17 @@ private ParamValueLoader findLoader(ParamKey paramKey, Field field) {
367376 }
368377 ParamKey key = paramKey .child (name );
369378
370- StringValueResolver resolver = resolverManager . resolver ( fieldType , spec );
371- if (null != resolver ) {
372- return new StringValueResolverValueLoader ( key , resolver , null , fieldType ) ;
379+ ParamValueLoader loader = paramValueLoaderOf ( spec , key . toString () );
380+ if (null != loader ) {
381+ return loader ;
373382 }
374383
384+ // Class fieldType = field.getType();
385+ // StringValueResolver resolver = resolverManager.resolver(fieldType, spec);
386+ // if (null != resolver) {
387+ // return new StringValueResolverValueLoader(key, resolver, null, fieldType);
388+ // }
389+
375390 return buildLoader (key , field .getGenericType (), spec );
376391 }
377392
0 commit comments