io.vertx.up.uca.di.JsrDi Maven / Gradle / Ivy
package io.vertx.up.uca.di;
import com.google.inject.AbstractModule;
import com.google.inject.name.Names;
import io.vertx.up.log.Annal;
import io.vertx.up.util.Ut;
import javax.inject.Named;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
/**
* Prepared
*
* @author Lang
*/
@Deprecated
public class JsrDi extends AbstractModule {
private static final Annal LOGGER = Annal.get(JsrDi.class);
private final transient ConcurrentMap, Set>> classes
= new ConcurrentHashMap<>();
public JsrDi(final ConcurrentMap, Set>> classes) {
this.classes.putAll(classes);
}
@Override
protected void configure() {
LOGGER.info("[ DI ] Jsr Bind Start......");
final Set ignored = new HashSet<>();
this.classes.forEach((interfaceCls, implSet) -> {
if (1 == implSet.size()) {
final Class impl = implSet.iterator().next();
LOGGER.info("[ DI ] 1 --> 1, Interface clazz bind = {0}, interface = {1}", impl, interfaceCls);
this.bind(interfaceCls).to(impl).asEagerSingleton();
} else {
implSet.forEach(implCls -> {
if (implCls.isAnnotationPresent(Named.class)) {
LOGGER.info("[ DI ] 1 --> 1, Interface named bind = {0}, interface = {1}", implCls, interfaceCls);
final Annotation annotation = implCls.getAnnotation(Named.class);
final String name = Ut.invoke(annotation, "value");
this.bind(interfaceCls).annotatedWith(Names.named(name))
.to(implCls).asEagerSingleton();
} else {
ignored.add(implCls.getName());
}
});
}
});
LOGGER.info("[ DI ] ?, Size = {0}, No definition!!!! Impl = {1}",
String.valueOf(ignored.size()), Ut.fromJoin(ignored));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy