typeliteral

Java inject implementation using TypeLiteral

我与影子孤独终老i 提交于 2019-12-24 00:46:02
问题 I have a project that provides an interface, let's call it IImplementMe, which i want to inject into my project. This interface will be implemented by various producers, so I need to inject all implementations. I am trying to use TypeLiteral for this. Here is the code of the producer : @Singleton public class SomeImplementation implements IImplementMe { private final String value; @Inject public SomeImplementation(final SomeOtherConfig configuration) { this.value= configuration.getValue(); }

Inject Generic Implementation using Guice

白昼怎懂夜的黑 提交于 2019-11-27 01:06:44
I would like to be able to inject a generic implementation of a generic interface using Guice. public interface Repository<T> { void save(T item); T get(int id); } public MyRepository<T> implements Repository<T> { @Override public void save(T item) { // do saving return item; } @Override public T get(int id) { // get item and return } } In C# using Castle.Windsor, I'd be able to do : Component.For(typeof(Repository<>)).ImplementedBy(typeof(MyRepository<>)) but I don't think the equivalent exists in Guice. I know I can use TypeLiteral in Guice to register individual implementations, but is

Inject Generic Implementation using Guice

依然范特西╮ 提交于 2019-11-26 12:26:12
问题 I would like to be able to inject a generic implementation of a generic interface using Guice. public interface Repository<T> { void save(T item); T get(int id); } public MyRepository<T> implements Repository<T> { @Override public void save(T item) { // do saving return item; } @Override public T get(int id) { // get item and return } } In C# using Castle.Windsor, I\'d be able to do: Component.For(typeof(Repository<>)).ImplementedBy(typeof(MyRepository<>)) but I don\'t think the equivalent