Skip to content

Commit

Permalink
Minor changes. New defects found.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberalexander committed Dec 24, 2021
1 parent 9fd36f6 commit ed7cbde
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public ApplicationContext(Config config) {
this.config = config;
}

public <T> T getObject(final Class<T> objectType) {
return this.getObject(objectType, "");
}

public <T> T getObject(final Class<T> objectType, final String genericType) {
//1. Creating KEY
ClassInfo<T> key = ClassInfo.of(objectType, genericType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.leonovich.winter.io.exceptions.WinterException;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.reflections.Reflections;

import javax.annotation.PostConstruct;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -52,9 +53,16 @@ public class ObjectFactory {
public ObjectFactory(final ApplicationContext applicationContext) {
this.context = applicationContext;

/*
Instantiate inner Reflections object here instead of using WinterReflections is required because
configurators search should be performed in winter-io package not in client app package, which passed to
WinterReflections
*/
//TODO think about if it's possible to instantiate WinterReflections with multiple packages
Reflections internalScanner = new Reflections("com.leonovich.winter.io");

//[1] Instantiating object configurators on ObjectFactory initialization
Set<Class<? extends ObjectConfigurator>> configuratorImplClasses = this.context.getConfig().scanner()
.getSubTypesOf(ObjectConfigurator.class);
Set<Class<? extends ObjectConfigurator>> configuratorImplClasses = internalScanner.getSubTypesOf(ObjectConfigurator.class);
for (Class<? extends ObjectConfigurator> clazz : configuratorImplClasses) {
configurators.add(clazz.getDeclaredConstructor().newInstance());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,15 @@ public void configure(Object t, ApplicationContext context) {
.filter(field -> field.isAnnotationPresent(InjectByType.class))
.forEach(field -> {
field.setAccessible(true);
Object injectCandidate = context.getObject(

//TODO Fix me
Object injectCandidate = context.getObject(field.getType(), field.getGenericType().getTypeName());
/*context.getObject(
field.getType(),
context.getConfig().scanner().extractGenericType(field)
);
);*/


/*
t - object for which field should be populated
injectCandidate - value which should be populated in field
Expand Down

0 comments on commit ed7cbde

Please sign in to comment.