Inject generic typer

9 views
Skip to first unread message

Asier

unread,
Nov 23, 2009, 3:24:23 AM11/23/09
to Google Guice mailing list
Hi all

How can I declare something like this in a module so it can be injected?

I have some mapbinders in different modules, and don't like to have lots of
semi-empty interfaces spreaded, so I've created a generic interface:

public interface IFactory<T extends IBuilder<T>> {
public T create(String type);
}

The objects in the mapbinder are expensive to build so I delay it's full
construction helping me with some builder:

public interface IBuilder<T extends IBuilder<T>> {
public T build() throws Exception;
}

The "final" interfaces are like this:

public interface IDataProvider extends IBuilder<IDataProvider> {
public void process(ISigner signer) throws Exception;
}

public interface ISigner extends IBuilder<ISigner> {
public byte[] sign(InputStream inStream) throws Exception;
}

There´s about five "final" interfaces, each one with 3-5 different
implementations.

Prior to this idea I was using five IBuilder interfaces. five IFactory
interfaces and binding them in his own modules, but I think it can be done
better, but I can't see how to inject generic types. I've readed about
TypeLiteral but I can't find a clear example, easy to understand.

Thanks

Asier

unread,
Nov 23, 2009, 3:47:25 AM11/23/09
to Google Guice mailing list
Asier escribió:

> public interface IBuilder<T extends IBuilder<T>> {
> public T build() throws Exception;
> }

Typo! The builder interface it's like this

public interface IBuilder<T> {
public T build() throws Exception;
}

Thanks
Reply all
Reply to author
Forward
0 new messages