You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Mark Addleman <ma...@bigfoot.com> on 2007/05/16 21:35:15 UTC

Using registry in a factory

I'd like to use tapestry-ioc outside the context of a web app but I'm running into a conceptual problem.  I need to create and destroy objects in response to asynchronous events, so I've defined the following interface:

public interface ServiceFactory
{
   public Service createService(Registry registry);
}

I pass the registry object so the service factory can look up all the necessary services in order to construct the particular service.  

I'd like the event publisher to be in the Tapestry Registry with the following interface:

public interface EventPublisher
{
    public void addServiceFactory(ServiceFactory factory);
}

The problem is, I don't know how to get the registry object into the EventPublisher's implementation.  Ideally, I'd like to inject the Registry into the EventPublisherImpl's constructor, but I know that's impossible under 5.0.4's implementation.  What do you think about enhancing injection to support this kind of bootstrapping?

Re: Using registry in a factory

Posted by Howard Lewis Ship <hl...@gmail.com>.
You can't get the Registry, but you can get an ObjectLocator, which includes
all the key methods of Registry.  This can be injected into your
ServiceFactory implementation.

On 5/16/07, Mark Addleman <ma...@bigfoot.com> wrote:
>
> I'd like to use tapestry-ioc outside the context of a web app but I'm
> running into a conceptual problem.  I need to create and destroy objects in
> response to asynchronous events, so I've defined the following interface:
>
> public interface ServiceFactory
> {
>    public Service createService(Registry registry);
> }
>
> I pass the registry object so the service factory can look up all the
> necessary services in order to construct the particular service.
>
> I'd like the event publisher to be in the Tapestry Registry with the
> following interface:
>
> public interface EventPublisher
> {
>     public void addServiceFactory(ServiceFactory factory);
> }
>
> The problem is, I don't know how to get the registry object into the
> EventPublisher's implementation.  Ideally, I'd like to inject the Registry
> into the EventPublisherImpl's constructor, but I know that's impossible
> under 5.0.4's implementation.  What do you think about enhancing injection
> to support this kind of bootstrapping?
>



-- 
Howard M. Lewis Ship
TWD Consulting, Inc.
Independent J2EE / Open-Source Java Consultant
Creator and PMC Chair, Apache Tapestry
Creator, Apache HiveMind

Professional Tapestry training, mentoring, support
and project work.  http://howardlewisship.com