Injection is only done on objects that the application model knows about. You are creating MyComposite
yourself so injection is not done.
You can do the injection yourself with something like:
MyComposite m = new MyComposite(parent, SWT.NONE);
ContextInjectionFactory.inject(m, context);
Note: this will not do injection in the constructor, use a @PostConstruct
method.
In any case field injection is not done until after the constructor has run, so your constructor code will never run with injection.
Update: You also only have @Named
on the field, you need @Inject
as well.
So your class needs to look like:
public class MyComposite extends Composite {
@Named("list")
@Inject
private HashMap<String, Ex> myMap;
public MyComposite(Composite parent, int style) {
super(parent, style);
}
@PostConstruct
void postConstruct() {
myMap.get("key");
}
}