Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package org.multi.parents;

import io.avaje.inject.RequiresBean;
import jakarta.inject.Singleton;
import org.multi.scope.Mod4Scope;

@Singleton
@Mod4Scope
// Generate `contains` method calls in `BeanIn4$DI` to test DBuilder checks parent scope
@RequiresBean({BeanIn1.class, BeanIn3.class})
public final class BeanIn4 {
private final BeanIn1 beanIn1;
private final BeanIn3 beanIn3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class ParentageTest {
@Test
Expand All @@ -14,6 +15,10 @@ void buildScopes() {
BeanScope parent = BeanScope.builder().parent(grandparent).modules(new Mod3Module()).build();
BeanScope scope = BeanScope.builder().parent(parent).modules(new Mod4Module()).build();
) {
assertTrue(scope.contains(BeanIn4.class));
assertTrue(scope.contains(BeanIn3.class));
assertTrue(scope.contains(BeanIn2.class));
assertTrue(scope.contains(BeanIn1.class));
BeanIn4 beanIn4 = scope.get(BeanIn4.class);
BeanIn3 beanIn3 = scope.get(BeanIn3.class);
BeanIn2 beanIn2 = scope.get(BeanIn2.class);
Expand Down
6 changes: 3 additions & 3 deletions inject/src/main/java/io/avaje/inject/spi/DBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DBuilder implements Builder {
/** The beans created and added to the scope during building. */
protected final DBeanMap beanMap = new DBeanMap();

protected final BeanScope parent;
protected final @Nullable BeanScope parent;
protected final boolean parentOverride;
/** Bean provided by the parent scope that we are not overriding. */
protected Object parentMatch;
Expand Down Expand Up @@ -378,12 +378,12 @@ public final boolean containsAllProfiles(List<String> type) {

@Override
public final boolean contains(String type) {
return beanMap.contains(type);
return beanMap.contains(type) || (parent != null && parent.contains(type));
}

@Override
public final boolean contains(Type type) {
return beanMap.contains(type);
return beanMap.contains(type) || (parent != null && parent.contains(type));
}

@Override
Expand Down