0

I have the following scenario shown below. When I run the class in a debugger the @Inject never hits for myInjectMethod. If I move the myInjectMethod to MyService it works. Why is this happening?

@Singleton
@Creatable
public class MyService extends MyBaseService {

    @Inject
    public MyService(final IEclipseContext context) {
        context.set(MyService.class.getName(), this);
    }
}

abstract class MyBaseService {
    @Inject
    public void myInjectMethod(@Preference(nodePath = "MyPreferenceName", 
           value = "MyPreferenceValue") final boolean isSomething) {
         // Why do I never get here when running the debugger?
         System.out.println("Hello");
    }
}
Wojciech Wirzbicki
  • 3,887
  • 6
  • 36
  • 59
user2992188
  • 283
  • 1
  • 5
  • 18

2 Answers2

0

Try moving the abstract class to its own file and making it public.

Which DI framework are you using? It might be that it doesn't support looking in super classes.

cole.markham
  • 352
  • 2
  • 5
  • It is in it's own class (although it kinda looks like the same class from the code snippet...sorry). It is the Eclipse RCP4 framework – user2992188 Feb 18 '15 at 16:37
  • I don't see any mention about limitations on their site https://wiki.eclipse.org/Eclipse4/RCP/Dependency_Injection – user2992188 Feb 18 '15 at 17:22
  • Oh, I missed the IEclipseContext reference, would have known if I had seen that. – cole.markham Feb 18 '15 at 19:24
  • I think this looks like a bug in the Eclipse DI framework. If you add a field to the package private abstract base class it will get injected but the methods do not. Can you file a bug at http://bugs.eclipse.org? – cole.markham Feb 19 '15 at 04:15
0

It seems the @Inject will not fire if the abstract class is package level. When I changed the abstract class to public, it started working.

user2992188
  • 283
  • 1
  • 5
  • 18