New issue 25 by ptit...@gmail.com: Support for empty collection injection
when there is no injection candidates
http://code.google.com/p/atinject/issues/detail?id=25
I post a new issue as it seems I can't reopen an existing issue.
So don't close this as a duplicate, but please answer this issue correctly.
You don't provide any consistent reason, neither #1 nor in #20, to not
inject empty collections when one knows there may not be any injection
candidate.
For instance:
interface StuffContributor {
}
class StuffUser {
@Inject
private Collection<StuffContributor> contributedStuff;
void aMethod() {
// Externally contributed stuffs
for (StuffContributor contributor : contributedStuff) {
// ...
}
}
}
I think the reason you get nulls instead of an empty collection is that
null is more informative, namely, no injection was defined. This is pretty
standard across all DI frameworks. I used to think the way you think about
this, but changed my mind to consider the null an important data point.
Either I got the wiring wrong, or someone using it got the wiring wrong.
If it is an optional wiring, you would be wise to log the null and continue
on so people know there's an injection point available (also, add an
@Named("contributedStuff" to the injection point so people know what to
call it.)