You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by foror <fo...@mail.ru> on 2009/02/12 16:48:10 UTC

Build same services with different Id (from dynamic list)

How to create services without "static bind(ServiceBinder)" and 
"buildMethod" like this:

AppModule {

    void contributeIdContainer(Configuration<String> config) {
        config.add("someId-1");
        config.add("someId-2");
    }
}

InternalModule {

  ...

    ids = idContainer.getAll();

    for (String id : ids) {
        // build() is imaginary method for create service
        build(MyService.class, 
objectLocator.getService(MyServiceFactory.class).createBy(id)
            .withId(id)
            .scope(PERTHREAD);
    }

  ...

}


SomeServiceImpl {

    public SomeServiceImpl(
        @InjectService("someId-1") MyService some1,
        @InjectService("someId-2") MyService some2  
    ) {...}
}

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


Re: Build same services with different Id (from dynamic list)

Posted by Howard Lewis Ship <hl...@gmail.com>.
Tapestry's IoC container runs in distinct stages; there's a setup
stage which involves the analysis to identify what services exist and
how they are built (i.e., including decoration, advice, lifecycle and
configuration) then the operational phase, and a short shutdown phase.

The ServiceBinder() has some methods that could accomplish what you
need, as long as the list of ids is known statically (does not involve
asking an IoC service for it).

Remember that services are not the only approach here.

I would define a Vendor service whose contributions where a
Map<String,MyService>.  Then you can ask Vendor for for a MyService by
id.

Better yet, you could define your own injection resolution annotation,
@InjectMyService("id"), and write an ObjectProvider for it that would
be contributed to the MasterObjectProvider.


On Thu, Feb 12, 2009 at 7:48 AM, foror <fo...@mail.ru> wrote:
> How to create services without "static bind(ServiceBinder)" and
> "buildMethod" like this:
>
> AppModule {
>
>   void contributeIdContainer(Configuration<String> config) {
>       config.add("someId-1");
>       config.add("someId-2");
>   }
> }
>
> InternalModule {
>
>  ...
>
>   ids = idContainer.getAll();
>
>   for (String id : ids) {
>       // build() is imaginary method for create service
>       build(MyService.class,
> objectLocator.getService(MyServiceFactory.class).createBy(id)
>           .withId(id)
>           .scope(PERTHREAD);
>   }
>
>  ...
>
> }
>
>
> SomeServiceImpl {
>
>   public SomeServiceImpl(
>       @InjectService("someId-1") MyService some1,
>       @InjectService("someId-2") MyService some2     ) {...}
> }
>
> ---------------------------------------------------------------------
> 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