You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Rico Landefeld <ri...@googlemail.com> on 2009/02/12 10:00:34 UTC

TAP5: Injecting dependencies into an ApplicationStateCreator

Hi, I try to inject a service into a application state creator, but when
create() is called, the service is not injected and I get a npe. But when I
inject this service into a page it works.

Here is my code:

public class FacetConfigurationsStateCreator implements
ApplicationStateCreator<Map<Facet, FacetConfiguration>>{

            @Inject
    private IFacetService facetService;

    @Override
    public Map<Facet, FacetConfiguration> create() { ..}

}

My AppModule:

    public void contributeApplicationStateManager(MappedConfiguration<Class,
ApplicationStateContribution> configuration)
    {

      configuration.add(Map.class, new
ApplicationStateContribution("session", new
FacetConfigurationsStateCreator()));
    }

Whats going wrong? Why gets the IFacetService not injected?

Re: TAP5: Injecting dependencies into an ApplicationStateCreator

Posted by Howard Lewis Ship <hl...@gmail.com>.
If you use Java's new keyword, then Tapestry IoC is not involved in
the creation of the FacetConfigurationsStateCreator.

You can inject a ServiceLocator object and have it autobuild() your
object; that will inject dependencies.

This is improved in Tapestry 5.1, there's an @Autobuild annotation and
other improvements.

On Thu, Feb 12, 2009 at 1:34 AM, Ulrich Stärk <ul...@spielviel.de> wrote:
> Please read http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html
> and specifically the part about dependency injection.
>
> HTH,
>
> Uli
>
> Rico Landefeld schrieb:
>>
>> Hi, I try to inject a service into a application state creator, but when
>> create() is called, the service is not injected and I get a npe. But when
>> I
>> inject this service into a page it works.
>>
>> Here is my code:
>>
>> public class FacetConfigurationsStateCreator implements
>> ApplicationStateCreator<Map<Facet, FacetConfiguration>>{
>>
>>            @Inject
>>    private IFacetService facetService;
>>
>>    @Override
>>    public Map<Facet, FacetConfiguration> create() { ..}
>>
>> }
>>
>> My AppModule:
>>
>>    public void
>> contributeApplicationStateManager(MappedConfiguration<Class,
>> ApplicationStateContribution> configuration)
>>    {
>>
>>      configuration.add(Map.class, new
>> ApplicationStateContribution("session", new
>> FacetConfigurationsStateCreator()));
>>    }
>>
>> Whats going wrong? Why gets the IFacetService not injected?
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: TAP5: Injecting dependencies into an ApplicationStateCreator

Posted by Ulrich Stärk <ul...@spielviel.de>.
Please read 
http://tapestry.apache.org/tapestry5/tapestry-ioc/service.html and 
specifically the part about dependency injection.

HTH,

Uli

Rico Landefeld schrieb:
> Hi, I try to inject a service into a application state creator, but when
> create() is called, the service is not injected and I get a npe. But when I
> inject this service into a page it works.
> 
> Here is my code:
> 
> public class FacetConfigurationsStateCreator implements
> ApplicationStateCreator<Map<Facet, FacetConfiguration>>{
> 
>             @Inject
>     private IFacetService facetService;
> 
>     @Override
>     public Map<Facet, FacetConfiguration> create() { ..}
> 
> }
> 
> My AppModule:
> 
>     public void contributeApplicationStateManager(MappedConfiguration<Class,
> ApplicationStateContribution> configuration)
>     {
> 
>       configuration.add(Map.class, new
> ApplicationStateContribution("session", new
> FacetConfigurationsStateCreator()));
>     }
> 
> Whats going wrong? Why gets the IFacetService not injected?
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org