Oh no, I just reread your post and saw the setImplementation() method using the getInstance(). Doh, my mistake. I'll try this and let you know how it works.
On Mon, Apr 20, 2009 at 12:08 PM, Brendan Haverlock < brend...@webreachinc.com> wrote: > Marcel, > > There is a bit of a problem with your approach. > > Dependency manager makes its own instance of Services.class when it > registers it as a server and uses this class to inject the service > references. So, every time I try to make a reference to the singleton, as > you can imagine, all the services are null. I was wondering what OSGi > magic > you could give me to get around this. I even tried to make the service > references static and had no avail. > > Thanks again for you help! > > Brendan Haverlock > > -----Original Message----- > From: Marcel Offermans [mailto:marcel.offerm...@luminis.nl] > Sent: Friday, April 17, 2009 2:38 PM > To: users@felix.apache.org > Subject: Re: Migrating a UI to OSGI > > 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 > > > -- Brendan Haverlock WebReach, Inc. Work: 949-255-5054 AIM: wr brendanh