Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:33:19+00:00 2026-06-16T08:33:19+00:00

I have created a OSGI service with declarative services to inject an object that

  • 0

I have created a OSGI service with declarative services to inject an object that implements an interface. If I inject the object in a class that is attached to the application model (handler,part,….) it is working fine. If I inject it in a class that is not attached to the application model it is always returning null.

Is it possible to use DI in classes that are not attached to the application model? I looked in the vogella tutorials but somehow I don’t find a solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:33:20+00:00Added an answer on June 16, 2026 at 8:33 am

    I know of three ways of how Eclipse 4 can inject objects in your classes:

    1. During start-up the Eclipse runtime looks for relevant annotations in the classes it instantiates.
    2. Objects injected in 1. are tracked and will be re-injected if changed.
    3. Manually triggering injection using the ContextInjectionFactory and IEclipseContext.

    What you want may be possible with the third option. Here is a code example:

        ManipulateModelhandler man = new ManipulateModelhandler();
    
        //inject the context into an object
        //IEclipseContext iEclipseContext was injected into this class
        ContextInjectionFactory.inject(man,iEclipseContext);
    
        man.execute();
    

    The problem is, however; that the IEclipseContext already needs to be injected into a class that can access the object that needs injection. Depending on the number of necessary injections, it might be more useful to use delegation instead (testability would be one argument).

        @Inject
        public void setFoo(Foo foo) {
            //Bar is not attached to the e4 Application Model
            bar.setFoo(foo);
        }
    

    Therefore, a better solution is probably using the @Creatable annotation.
    Simply annotate your class, and give it a no-argument constructor.

       @Creatable
       public class Foo {
           public Foo () {}
       }
    

    Using @Inject on that type as in the method above, will let Eclipse instantiate and inject it.
    The disadvantage is that you cannot control the object creation anymore, as you would with ContextInjectionFactory.inject(..).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an OSGi bundle with an exposed (declarative) service. If I, when
I have created an android application that calls (using kSOAP library) a SOAP based
I have a Java application. I created a OSGi bundle and in Activator.start i
I have services that need to be created on a per-configuration base, each of
We have created a web service using JAX-WS and ProSyst OSGi. Accessing the service
I have created a class that extends IntentService, and I would like to start
I have created some JQuery that will expand a div 'popup' on hover and
I have created a JSP / servlets application running in Tomcat 7. It runs
I have created a function that shows/hides different messages according to a combination of
I have created a dialog and got a problem that only part of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.