Dilanka Muthukumarana
2018-10-03 11:47:52 UTC
Hi All,
Currently I am working in Guice injection related development and
experiencing injection problem with multiBind with optional= true.
In guice-4.0, I have seen skipping injection if it is optional.
code location: MembersInjectorStore.java
Method:
/**
* Returns the injectors for the specified injection points.
*/
ImmutableList<SingleMemberInjector> getInjectors(
Set<InjectionPoint> injectionPoints, Errors errors) {
List<SingleMemberInjector> injectors = Lists.newArrayList();
for (InjectionPoint injectionPoint : injectionPoints) {
try {
Errors errorsForMember = injectionPoint.isOptional()
? new Errors(injectionPoint)
: errors.withSource(injectionPoint);
SingleMemberInjector injector = injectionPoint.getMember() instanceof Field
? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember)
: new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
injectors.add(injector);
} catch (ErrorsException ignoredForNow) {
// ignored for now
}
}
return ImmutableList.copyOf(injectors);
}
My code is like below:
private Set<WarningInfoClientPlugin> warningInfoClientPlugins;
@Inject(optional = true)
public void setWarningPlugins(final Set<WarningInfoClientPlugin> warningInfoClientPlugins)
{
this.warningInfoClientPlugins = warningInfoClientPlugins;
}
Code is perfectly working *without* *optional = true* attribute.
Appreciate your help on this. Thank you.
Regards,
Dilanka
Currently I am working in Guice injection related development and
experiencing injection problem with multiBind with optional= true.
In guice-4.0, I have seen skipping injection if it is optional.
code location: MembersInjectorStore.java
Method:
/**
* Returns the injectors for the specified injection points.
*/
ImmutableList<SingleMemberInjector> getInjectors(
Set<InjectionPoint> injectionPoints, Errors errors) {
List<SingleMemberInjector> injectors = Lists.newArrayList();
for (InjectionPoint injectionPoint : injectionPoints) {
try {
Errors errorsForMember = injectionPoint.isOptional()
? new Errors(injectionPoint)
: errors.withSource(injectionPoint);
SingleMemberInjector injector = injectionPoint.getMember() instanceof Field
? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember)
: new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
injectors.add(injector);
} catch (ErrorsException ignoredForNow) {
// ignored for now
}
}
return ImmutableList.copyOf(injectors);
}
My code is like below:
private Set<WarningInfoClientPlugin> warningInfoClientPlugins;
@Inject(optional = true)
public void setWarningPlugins(final Set<WarningInfoClientPlugin> warningInfoClientPlugins)
{
this.warningInfoClientPlugins = warningInfoClientPlugins;
}
Code is perfectly working *without* *optional = true* attribute.
Appreciate your help on this. Thank you.
Regards,
Dilanka
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ee4a5435-a317-497a-a044-4175f4c9340b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/ee4a5435-a317-497a-a044-4175f4c9340b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.