[jsr330-eg] Issue 20 in atinject: make Injection optional

52 views
Skip to first unread message

atin...@googlecode.com

unread,
Dec 2, 2009, 2:34:55 AM12/2/09
to atin...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 20 by zhouyanming: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

like @Autowired(required=false) in spring

@Inject(required=false)
private UserService userService;

or

@Inject
@Optional
private UserService userService;

--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings

--

You received this message because you are subscribed to the Google Groups "atinject" group.
To post to this group, send email to atin...@googlegroups.com.
To unsubscribe from this group, send email to atinject+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/atinject?hl=en.


atin...@googlecode.com

unread,
Feb 8, 2010, 2:00:36 PM2/8/10
to atin...@googlegroups.com

Comment #1 on issue 20 by mccallum.michael: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

That example is a bit contrived. How about injection of listeners to a
repository

public class UsefulRespository {

@Inject
Collection<UsefulUpdateListener> listeners

public void update(Useful u) {
store.replace(u);
for (UsefulUpdateListener l: listeners) {
l.notify(u);
}
}
}

The key aspect is that the repository does not care if there are listeners
but
provides the facility to notify them. Ideally if there were listeners they
would be
injected and if not an empty collection. I've been doing this for a long
time in
Spring using required=false and testing for nullity.

Obviously @Optional or @Required could be used to force it
not-null/not-empty but
have an indication that implementors do something consistent with
collections would
be really useful.

atin...@googlecode.com

unread,
Feb 8, 2010, 4:55:56 PM2/8/10
to atin...@googlegroups.com

Comment #2 on issue 20 by gavin.king: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

Surely an empty collection represents "no listeners". So I don't understand
your
usecase. You would only need some special "optional injection" feature if
you wanted
to inject null, not if you want to inject an empty collection.

atin...@googlecode.com

unread,
Feb 8, 2010, 8:07:18 PM2/8/10
to atin...@googlegroups.com

Comment #3 on issue 20 by limpbizkit: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

You could use something like Guice's multibindings to populate an
initially-empty set
with values. http://code.google.com/p/google-guice/wiki/Multibindings

atin...@googlecode.com

unread,
Feb 9, 2010, 7:57:59 AM2/9/10
to atin...@googlegroups.com

Comment #4 on issue 20 by zhouyanming: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

such feature implemented by both guice and spring,so why not add support in
jsr-330?

atin...@googlecode.com

unread,
Oct 18, 2010, 7:46:36 PM10/18/10
to atin...@googlegroups.com
Updates:
Status: Duplicate

Comment #5 on issue 20 by crazyboblee: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

We decided against supporting optional injection in JSR-330:
http://code.google.com/p/atinject/issues/detail?id=1&can=1&q=optional

atin...@googlecode.com

unread,
Oct 18, 2010, 9:48:30 PM10/18/10
to atin...@googlegroups.com

Comment #6 on issue 20 by zhouyanming: make Injection optional
http://code.google.com/p/atinject/issues/detail?id=20

how about provide a @Optional qualifier?

Reply all
Reply to author
Forward
0 new messages