Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Dependency Injection in Abstract Classes
Dependency Injection in Abstract Classes [message #782316] Mon, 23 January 2012 14:18 Go to next message
Tom K. is currently offline Tom K.Friend
Messages: 22
Registered: July 2009
Junior Member
What are the rules for dependency Injection in abstract classes ?
P.Ex. I need a EModelService or anything injected in a abstract Part class.
Somehow the @Inject and @PostConstruct aren't called, even if they are correctly called in the impleneting concrete Part class.

Thanks for some hints...
Re: Dependency Injection in Abstract Classes [message #782804 is a reply to message #782316] Tue, 24 January 2012 13:41 Go to previous messageGo to next message
Eclipse UserFriend
I'm 99% certain My app relies on injection for methods and fields on abstract classes. I've never tried marking an abstract method as being injectable though.

You can see the relevant source in InjctorImpl in the methods processMethods(), isOverridden(

git.eclipse.org/c/platform/eclipse.platform.runtime.git/tree/bundles/org.eclipse.e4.core.di/src/org/eclipse/e4/core/internal/di/InjectorImpl.java

From a quick glance, I can't see anything filtering out abstract methods.

I suggest that you create a small test case demonstrating the problem and attach it to a bug prefixed with "[DI]" at

bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform&component=Runtime
Re: Dependency Injection in Abstract Classes [message #783367 is a reply to message #782804] Wed, 25 January 2012 15:43 Go to previous messageGo to next message
Eclipse UserFriend
Tom, is it possible that your abstract class and the concrete classes are defined in different packages?
Re: Dependency Injection in Abstract Classes [message #783501 is a reply to message #783367] Wed, 25 January 2012 20:52 Go to previous message
Eclipse UserFriend
I asked the Di implementor, Oleg, about this and he said:

Quote:

The strange thing about annotations is that they are not inherited:
Class A { 
        @Inject 
        void method1(arg) {...}; 
} 

ClassB extends ClassA { 
        void method1(arg) {...}; 
} 

Attempt to inject ClassB won't trigger method1 as it is considered to be non-injectable. (There are tests for this in the JSR on the dependency injection and the same logic is used for other Java annotations.)


In looking through my code, my abstract injections were all on fields, not methods.
Previous Topic:CSS: 'background-image' does not work
Next Topic:problem with org.eclipse.ui.internal.MakeHandlersGo
Goto Forum:
  


Current Time: Tue Apr 23 15:01:08 GMT 2024

Powered by FUDForum. Page generated in 0.03416 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top