How can the class that @Injects a @Dependent class pass information to its constructor?

132 views Asked by At

My problem is probably best explained with some sample code:

@Named
public class Search {
    @Inject @Select(Type.SEARCH)
    private Criteria criteria;
}

@Named
public class Selection {
    @Inject @Select(Type.SELECTION)
    private Criteria criteria;
}

public class Criteria {
    private final List<Selection> statics;
    private final List<Selection> choosables;

    @Inject
    public Criteria(
            @Any Instance<List<Selection>> statics,
            @Select(Type.CHOOSABLE) List<Selection> choosables,
            InjectionPoint ip) {
        Select sel = ip.getAnnotated().getAnnotation(Select.class);
        this.statics = cloneList(statics.select(sel).get());
        choosables = cloneList(choosables);
    }
}

The idea is that Criteria has all the logic to deal with lists of Selection objects, but the actual lists to manage vary depending on the user of the Criteria class. As it stands, Weld complains about being unable find a class with the matching qualifiers, since Criteria isn't annotated @Select. So - can I make Criteria eligible for injection no matter the @Select qualifier? Or is there another way to pass that piece of information to the Criteria class?

Edit: turns out, the question has already been asked in a similar form here.

0

There are 0 answers