Hi folks,
I'm developing applications which are based on OSGi. In 80%-90% of my
time I don't use the hot plugging ability of OSGi but rather the
component and service based development possibilities. Even though I
don't need the hot plugging ability I need to use the cumbersomely
SerivceTracker to retrieve my services. It was a pain to write a
ServiceTracker with addingService() and removedService() methods for
each service even though each ServiceTracker is almost doing the same
stuff.
So I decided to look for a better solution. From my point of view the
Spring Dynamic Modules approach is just to heavy weighted and to
handle all those XML-files is a different pain. Afterwards I found an
approach called "Peaberry" but this approach depends on annotations
which have other disadvantages.
At the end of the day I wrote my own Dependency-Injection approach
which is based on OSGi. I would like to ask you whether there is
something similar to this so I don't need to reinvent the wheel again.
Here's the code how I do inject a service.
private ServiceTracker _tracker;
private AccountManagerImpl _accountManager;
public void start(BundleContext context) throws Exception {
_accountManager = new AccountManagerImpl();
/*
* This does create a ServiceTracker for the given service. When
addingService(...) or removedService(...) methods are called, the
appropriate bindXYZService(...) and unbindXYZService(...) methods are
called on the given object (_accountManager).
*/
_tracker = bindService(IAccountService.class,
context).toObject(_accountManager);
_tracker.open();
}
// The serviceTracker is closed within the stop-Method
public void stop(BundleContext context) throws Exception {
_tracker.close();
}
I expect the _accountManager to have a "bind"-Method with
IAccountService as a parameter:
public void bindAccountService(IAccountService accountService) {
_accountService = accountService;
}
I would really appreciate if someone could help me to solve my problem.
Cheers,
Eugen_______________________________________________
OSGi Developer Mail List
[email protected]
https://mail.osgi.org/mailman/listinfo/osgi-dev