Links
- ColdFusion Design Patterns
- Minecraft Papercraft Minecraft Fan? You might like my newish Minecraft Papercraft site!
- Object Oriented ColdFusion
Pages
Categories
Tags
Abstraction Ant Apache Autocomplete CFCUnit CodexWiki ColdFusion Components Constants CSS DAO Dates Dependency Injection Design Patterns File Flash Forms Frameworks Gateways Groovy Guice Hosting HTML IIS Java JavaScript jQuery Mappings MSSQL MySQL Nested Set Trees OOP pagination Python Railo Security SES URLs Spring Strategy Timestamp Tomcat Tools Ubuntu Unit Testing ValidationArchives
- February 2012
- June 2011
- February 2011
- January 2011
- December 2010
- September 2010
- July 2010
- May 2010
- April 2010
- November 2009
- July 2009
- June 2009
- August 2008
- June 2008
- May 2008
- March 2008
- November 2007
- October 2007
- September 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006

Google Guice AssistedInject example in Groovy
If you are using Google Guice to manage your object dependencies then you may find a situation where you have a constructor that has parameters required from Guice and some parameters from the calling code.
For example, suppose you are creating a Book which requires a BookService and a name when it is created:
In this case we want the BookService to be injected by Guice, but the name to be supplied by the calling code.
Guice provides something called an AssistedAnnotation that can help in this situation.
First, for assisted annotations to work you will need the following jars (which are all available within the downloads at the Guice download site):
Let’s take a look at some example code.
AssistedInject with different parameter types
AssistedInject with the same parameter types
If some of our parameters are of the same type, then we need to distinguish between then with some additional modified annotations.
Let’s add an author to our Book constructor, which is also a String.