struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeromy Evans <jeromy.ev...@blueskyminds.com.au>
Subject Re: xwork and DI
Date Tue, 22 Apr 2008 02:57:27 GMT
Musachy Barroso wrote:
> If I want to add a constant that can be injected in one of xwork
> classes (like "devMode" for example), what do I need to do? Just
> adding @Inject and defining the constant in default.properties in core
> doesn't work. I don't know much about this whole guice black magic
> thing :)
>
> musachy
>
>   
Here's some simple examples:

Setup some beans and constants in the Container with unique names:

http://code.google.com/p/struts2urlplugin/source/browse/trunk/struts2-url-plugin/src/main/resources/struts-plugin.xml

eg. 1. Inject constant into a bean

http://code.google.com/p/struts2urlplugin/source/browse/trunk/struts2-url-plugin/src/main/java/com/blueskyminds/struts2/urlplugin/URLPatternActionMapper.java
Line 333
   @Inject("struts.urlplugin.actionMapConfiguration")
    public void setMappingConfigurationName(String 
mappingConfigurationName) {
        this.mappingConfigurationName = mappingConfigurationName;
    }

eg. 2. Inject Container into a bean to enable run-time lookup by name 
and class:
   @Inject
    public void setContainer(Container container) {
        this.container = container;
    }
  Line 116
   mappingConfiguration = 
container.getInstance(ActionMapConfiguration.class, 
mappingConfigurationName);

eg. 3. Inject Bean into another bean directly: exactly as per the 
container injection.  If there's only one instance it will bind, 
otherwise specify the name, otherwise it will fail.
@Inject("defaultActionMapper")
public void setActionMapper(ActionMapper actionMapper) {...

It only gets complicated when you need to mix injection with beans 
created outside the container, as described by Wes.

cheers,
 Jeromy Evans

PS. this is far inferior to the current functionality of Guice.









---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message