com.github.nill14.utils.moduledi.guice.GuiceBeanInjector Maven / Gradle / Ivy
package com.github.nill14.utils.moduledi.guice;
import com.github.nill14.utils.init.api.IBeanInjector;
import com.github.nill14.utils.init.api.IParameterType;
import com.google.common.reflect.TypeToken;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.TypeLiteral;
@SuppressWarnings("unchecked")
public class GuiceBeanInjector implements IBeanInjector {
private final Injector injector;
public GuiceBeanInjector(Injector injector) {
this.injector = injector;
}
@Override
public void injectMembers(Object bean) {
injector.injectMembers(bean);
}
@Override
public T wire(Class beanClass) {
return injector.getInstance(beanClass);
}
@Override
public T wire(TypeToken typeToken) {
return (T) injector.getInstance(Key.get(TypeLiteral.get(typeToken.getType())));
}
@Override
public T wire(IParameterType type) {
return (T) wire(TypeToken.of(type.getGenericType()));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy