How to use Dependency Injection in GLSP? #677
-
Hi, I am trying to use Guice Dependencies in my GLSP Server module. But nothing seems to work. My first thought was that this should be super easy. First I declare an Interface public interface BPMNExtensionHandler {
String getUISchema(BPMNBaseElement element);
} Next I do some implementation of that interface: public class BPMNEventExtensionHandler implements BPMNExtensionHandler {
public BPMNEventExtensionHandler() {
super();
}
@Override
public String getUISchema(final BPMNBaseElement element) {
return null;
}
} Now I can inject this handler via my interface somewere in my code: public class EventNodeBuilder extends AbstractGNodeBuilder<EventNode, EventNodeBuilder> {
@Inject
protected BPMNExtensionHandler bpmnExtension;
@Override
public void setProperties(final EventNode node) {
.....
// call extension.....
if (bpmnExtension != null) {
System.out.println("-------_> go");
}
}
} and finally I need to bind my implementation in my DiagramModule. I tried everything, but nothing works.... public class BPMNDiagramModule extends DiagramModule {
@Override
protected void configureBase() {
super.configureBase();
// bind(BPMNEventExtensionHandler.class).in(Singleton.class); // does not work
// does even not work
bind(BPMNExtensionHandler.class).to(BPMNEventExtensionHandler.class);
}
} My injected BPMNExtensionHandler is always null. Also the constructor is never called. What did I wrong? I notice that there are tons of code in GLSP providing some kind of helper methods for using Guice dependencies - registries, binding methods, abstract classes, helper classes..... But it is impossible for me to guess what all this code is good for. For example - what is the class Can someone provide me an example? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Ralph, The dependency-injection creates a graph of objects. |
Beta Was this translation helpful? Give feedback.
Hi Ralph,
The dependency-injection creates a graph of objects.
@Inject
can only be used inside of objects that were also created via dependency-injection. So I think the first question is: how is your EventNodeBuilder created?