How services work

From RifidiWiki

Revision as of 21:48, 3 June 2008 by Jochen (Talk | contribs)

Jump to: navigation, search

Why services

The first version of Designer (and also the rest of Rifidi) was littered with a lot of Singletons.
As everybody knows by now:

  • Singletons are bad.
  • They are hard to test.
  • Impossible (almost) to mock

So I replaced them with a little service registry where you register a concrete class with an interface this class implements.
Once again I had to discover that somebody else had already had that idea some time ago.
OSGi is an SOA (bright me, reading about OSGi all the time without actually realizing what it means).
So I am using now the OSGi ServiceRegistry to deal with services.
You, as an aspiring rifidi developer, won't need to worry about that.
To make it easier to use the services I wrote a ServiceLocater that does all the work for you.
The only thing to remember is to use the @Inject annotation and do the following call in the constructor.

ServiceRegister.getInstance().service(this)
Personal tools