2
votes

I'm trying to porting an E3.X application to E4 and following an tutorial by Lars Vogel. I created a view wrapper which extends the DIViewPart class, the view itself which uses dependency injection on the constructor and referenced the view wrapper in my plugin.xml.

However, when firing up the application an exception is thrown:

org.eclipse.e4.core.di.InjectionException: Could not find satisfiable constructor in my.application.views.MyView

I have no idea what is going wrong even after several hours of googling. Maybe I'm just searching for the wrong things, but I'm pretty clueless right now. I would be happy if someone could point me out what I'm missing.

Just to be sure I appended the affected views source code below:

public class MyViewWrapper extends DIViewPart {

    public MyViewWrapper() {
        super(MyView.class);
    }

}
public class MyView {

    public static final String ID = MyView.class.getCanonicalName();

    private Label label;

    @Inject
    public MyView(Composite parent) {
        this.label = new Label(parent, SWT.NONE);
        this.label.setText("My view");      
    }

}

Any help is appreciated and thanks in advance.

Edit: Stefan pointed out that the issue might be related to the fact that e4 does not know the right composite during the constructor call and that the following code should do the trick:

public class MyView {

    public static final String ID = MyView.class.getCanonicalName();

    private Label label;

    public MyView() { }

    @PostConstruct
    public void createPartControl(Composite parent) {
        this.label = new Label(parent, SWT.NONE);
        this.label.setText("Sensor view");              
    }

}

Sadly this was not the case. The exception changed but the cause might still be the same:

org.eclipse.e4.core.di.InjectionException: Unable to find matching method to invoke

My assumption is that dependency injection as a whole is not working correctly, but I have no idea why, since I've done everything exactly as in the tutorials I've found. Do I need to add a .e4xmi or something?

1
The parent component is unknown when the part is created. It is provided later when the part control is created (in createPartControl()). Therefore e4 does not have an appropriate instance of Composite to inject into the constructor. This causes the exception. However I did not try DI in e3. - Stefan
This sadly did not solved the issue. I edited the starting post to reflect this. - Jan Gräfen
In my case, the actual problem wasn't the absence of a satisfiable constructor, but the absence of an actual argument (an EditorReference) in the context. That in turn was ultimately caused by not including the plug-in org.eclipse.equinox.event. - Andy Thomas

1 Answers

0
votes

I encountered the same situation as you and was able to find out the solution by debugging the code.

Look at your stack trace, more specifically at the org.eclipse.e4.core.internal.di.InjectorImpl class, around line 213. The invoke method receives a qualifier parameter that is the target of the matching method mentioned in the error message. This quantifier is what the dependency injection is looking for.

For example, in my case, the quantifier parameter was a @Focus annotation. So by adding the @Focus annotation on a proper method in MyView class, I was able to get rid of that second problem that you described, because DI found the right matching method to call.

I know it's a late answer to a question asked a few months ago, but I thought this could help someone else to debug this without spending too much time.