If I understand your requirement, you are using ListenerDispatcher static
method as a factory method to inject an instance of ListenerInterface. Why
can't you inject ListenerInterface implementation into ListenerDispatcher.
You can bind different implementations of ListenerInterface using
annotations.
public class ListenerDispatcher {
@Inject
public ListenerDispatcher(@Named("abc") ListenerInteface) {
...
}
}
In your module implementation, you can do
bind(ListnerInferace.class).annotatedWith(Names.named("abc)).to(ListenerInterfaceImpl.class);
On Fri, Nov 12, 2010 at 2:14 PM, [email protected] <
[email protected]> wrote:
> Hello list,
>
> Inspired by the neat configuration Module for guice persist, I decided
> to make something similar for a small subpart of my project. I'm not
> fully sure how to create it though.
>
> I want to create a module which sets up the relationship between
> listeners and dispatchers in an event system. The event system is
> based on a class called ListenerDispatcher<T> [1]. I want the module
> to work something like this:
>
> protected void configureEvents() {
> connect(ListeningInterface.class,
> ClassImplementingListeningInterface.class);
> // .... and so on
> }
>
> protected void configure() {
> configureEvents();
> }
>
> What I want that line to do is:
>
> ListenerDispatcher<ListeningInterface> listenerDispatcher =
> ListenerDispatcher.create(ListeningInterface.class);
> listenerDispatcher.addListener(classImplementingListeningInterface);
>
> Initially I wouldn't need to be able to configure the scope of the
> binding. I just want to reduce the boiler plate to that single line
> (compared to a lot of configuration atm). My initial thoughts is that
> I store all the connect bindings in a map or similar until the
> configure() method of AbstractModule is run. In configure I bind/
> create all the ListenerDispatchers. So far it's fine, I'm not just
> sure how to runt the addListener part.
>
> Thanks for any pointers or help!
>
> [1] http://pastie.org/private/e20zdyb9nwbmjgq9vgkjhw
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "google-guice" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-guice%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-guice?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-guice?hl=en.