struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wes Wannemacher <w...@wantii.com>
Subject Re: xwork and DI
Date Tue, 22 Apr 2008 02:12:07 GMT
Not the object you are injecting, but the object that is being
injected... 

Like here - 

http://struts.apache.org/2.x/struts2-core/apidocs/com/opensymphony/xwork2/inject/Container.html

Foo has dependencies injected, but if you instantiate it as 

Foo foo = new Foo();

Then you won't get anything injected. But, if you want a fully injected
copy of Foo, you need to get it from the container - 

Foo foo = c.inject(Foo.class);

So, if you are '@Inject'ing your String, you have to make sure that the
object that you are trying to read your String from is created by the
Container.

An easy example is com.opensymphony.xwork2.ObjectFactory, the method - 

public Object buildBean(String className, Map extraContext, boolean
injectInternal) throws Exception 

which calls - 

protected Object injectInternalBeans(Object obj) {
        if (obj != null && container != null) {
            container.inject(obj);
        }
        return obj;
    }

IIRC, all beans pass through here at some point.

-Wes



On Mon, 2008-04-21 at 21:52 -0400, Musachy Barroso wrote:
> It is just an string, like "devMode".
> 
> musachy
> 
> On Mon, Apr 21, 2008 at 8:00 PM, Wes Wannemacher <wesw@wantii.com> wrote:
> > Musachy,
> >
> >  Is your object (injectee) instantiated by the container? I think there
> >  is some work to do after instantiating so that the dependencies can be
> >  injected.
> >
> >  -Wes
> >
> >
> >  On Mon, 2008-04-21 at 14:37 -0400, 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
> >  >
> >
> >
> >  ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> >  For additional commands, e-mail: dev-help@struts.apache.org
> >
> >
> 
> 
> 


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


Mime
View raw message