On Apr 17, 2009, at 23:19 , Brendan Haverlock wrote:

Thanks for the replies guys!

You're welcome.

Well, this is so odd though because I mean a lot of my components take in parameters to the constructor and I don't just have one instance of that component. I make multiple components based on what params are passed in. Setting the implementation class will just inject into one instance of these classes. And, a lot of times these UI components need to make calls to other services from their constructor, so adding them to the manager breaks
them because the other services aren't injected at that point.

Another way is to have one "singleton" in your bundle that has all service references. A singleton inside an OSGi bundle will be local to that bundle, and if you don't export it, nobody else can see it, so from a design point of view it's not that bad.

So start with something like:

manager .add(createService().setImplementation(Services.getInstance()).add( /* all dependencies you need */ ));

and have a Services class something like:

public class Services {
  public static Services instance;
public static Services getInstance() { /* implement singleton here */ };
  public volatile MyFirstInjectedService m_s1;
  public volatile MySecondInjectedService m_s2; // etc..
}

and use them in your Swing components like this:

  Services.getInstance().m_s1.invokeSomeMethod();

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@felix.apache.org
For additional commands, e-mail: users-h...@felix.apache.org

Reply via email to