java - CDI Extension - How to handle nonbinding values on qualifier -
i working on cdi extension. have register special custom beans, thats why producer not sufficient.
this done inside afterbeandiscovery
-phase registering custom implementation of bean<>
using abd.addbean()
method.
the drawback inside create()
-method of bean can't access injectionpoint
, may contain additional configuration inside annotation.
as possibility collect beans need in processinjectiontarget
phase (as there have access annotations) , register each of them inside afterbeandiscovery
phase. have make configuration annotation qualifier , attributes of qualifier binding (not using @nonbinding
) prevent ambigous dependencies.
but register huge amount of beans different in configuration.
is there alternate solution? possible access injectionpoint
inside beans create()
method?
thank you!
i think found solution.
basically somehow needed access current injectionpoint
inside beans create()
method, way 1 can access annotations of injection point.
to injection point following code snipped works (inspired omnifaces, using apache deltaspike):
public class injectionpointgenerator { @inject private injectionpoint injectionpoint; public injectionpoint getinjectionpoint() { return injectionpoint; } } public class beanutils { protected beanutils() { // prevent instantiation } public static injectionpoint getinjectionpoint(@nonnull creationalcontext context) { bean<injectionpointgenerator> bean = getbean(injectionpointgenerator.class); beanmanager beanmanager = beanmanagerprovider.getinstance().getbeanmanager(); injectionpoint injectionpoint = bean.getinjectionpoints().iterator().next(); return (injectionpoint) beanmanager.getinjectablereference(injectionpoint, context); } private static <t> bean<t> getbean(@nonnull class<t> type) { return beanprovider.getbeandefinitions(type, false, true).iterator().next(); } }
Comments
Post a Comment