Issue 749 in google-guice: Add support for injection into non-static inner classes

8 views
Skip to first unread message

google...@googlecode.com

unread,
May 17, 2013, 2:21:49 PM5/17/13
to google-g...@googlegroups.com
Status: New
Owner: ----

New issue 749 by FireW...@gmail.com: Add support for injection into
non-static inner classes
http://code.google.com/p/google-guice/issues/detail?id=749

Description of the issue:
New feature. Support injection into inner classes that are not static.

Using guice-3.0.

When I last used Jboss 4.x w/ EJB 3.0 (like 6-7 year old technology) - it's
@EJB injection supported injection into (non-static) inner classes. I also
believe that more modern CDI via javax.inject.Inject - @Inject also
supports injection into (non-static) inner classes. It would be nice if
Guice supported this.

By not supporting this, it requires class refactoring / restructuring into
more complex forms for the sole purpose of making Guice injection work
which is kind of crazy.

Steps to reproduce:
1. Create a class which holds a non-static inner class which uses guice
@Inject (com.google.inject.Inject) to try to inject a resource.
2. Execute the code
3. Receive error message:

Caused by: com.google.inject.ConfigurationException: Guice configuration
errors:

1) Injecting into inner classes is not supported. Please use a 'static'
class (top-level or nested) instead of
<some.package.OutterClassName$InnerClassName>

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

google...@googlecode.com

unread,
May 17, 2013, 3:36:43 PM5/17/13
to google-g...@googlegroups.com

Comment #1 on issue 749 by FireW...@gmail.com: Add support for injection
Hrmm I don't see how to edit this. Close the issue, i was misunderstanding
what the problem was. Thought it was because i was using injection in my
inner class but i was trying to inject my inner class (so I could use
@Transactional). I'm not sure if that is supported by other injection
frameworks or not.

google...@googlecode.com

unread,
May 17, 2013, 4:31:49 PM5/17/13
to google-g...@googlegroups.com
Updates:
Status: WorkingAsIntended

Comment #2 on issue 749 by mccu...@gmail.com: Add support for injection
Closing as requested.

PS. I think Spring might support injection of non-static inner classes, by
relying on the fact that the inner class has an implicit constructor that
accepts a reference to the outer instance. However, you can only create the
inner instance inside the context of an outer instance (ie. when
configuring with nested XML) and there are gotchas:
http://stackoverflow.com/questions/15783854/how-to-define-a-bean-for-an-non-static-inner-class-in-spring-avoiding-circula
Reply all
Reply to author
Forward
0 new messages