Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow named injections #163

Merged
merged 3 commits into from
Sep 8, 2020
Merged

Allow named injections #163

merged 3 commits into from
Sep 8, 2020

Conversation

applitect
Copy link
Collaborator

No description provided.

@@ -401,7 +402,9 @@ private final void configureConstructorInjection() {
fields.get(clazz).forEach(field -> {
log.trace("Inject target> Field: ({}) Decorator: ({})", field, decorator);
try {
Object value = getInjectableValue(field.getAnnotation(decorator), field.getName(), clazz, msg);
String fieldName = Optional.ofNullable(field.getAnnotation(Named.class))
.map(a -> a.value()).orElse(field.getName());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you want orElse or orElseGet? orElse is always executed where as orElseGet is not

@@ -224,6 +229,49 @@ public void testHeadersAndProperties() {
assertEquals(ec.producer, "testing");
}

// For the next two tests, we are testing named dependency injection.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor Opinion: This comment seems a little brittle in that code methods could move

static Map<String, Person> map = new HashMap<>();

@BeanResolver
public Object resolve(Class<?> requestedClass, String name){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does scope matter at all? It looks like if we have a named bean then we are applying Singleton scope and if we have a non-named bean we are creating new instances on every request

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, since it it only being used in the tests to prove that the named annotation resolver can be used successfully. This is not production level code.

@applitect applitect merged commit 2c49ec4 into develop Sep 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants