Hello Arjun,

On Sep 18, 2008, at 12:57 , Arjun Panday wrote:

I've been playing with DependencyManager recently and I must say i find the design and syntax extremely elegant and also much more traceable than the SCR.

Thanks. :)

So much so that I was about to remove all my DeclarativeService XMLs to replace them with a few lines of DependencyManager when i bumped into an issue: I sometimes have a dependency on a class (as opposed to an interface), but this is made impossible in DependencyManager because of the use of proxies. Here's a typical error i get when i try to bind a specific classloader: java.lang.IllegalArgumentException: java.lang.ClassLoader is not an interface
      at java.lang.reflect.Proxy.getProxyClass(Proxy.java:362)
      at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at org .apache .felix .dependencymanager .ServiceDependency.getNullObject(ServiceDependency.java:96)

But i guess it would be the same if i was to bind any implementation of an abstract class.

Yes it would. If a service is not available, the dependency manager will use the Null Object Pattern to inject an object that "does nothing". The ServiceDependency.getNullObject() is implemented using dynamic proxies, which only work on interfaces.

I'd be quite sad to have to abandon DependencyManager for this reason.. Does anyone know of a workaround, or a future release that would address this issue?

For now, you might be able to work around this issue. For one, these null objects will only be injected if you have optional dependencies and you use automatic injection for them. So if you can avoid that combination, that would help.

You can turn off injection for a ServiceDependency by configuring it with setAutoConfig(false) and still get notifications using callbacks.

Up to now I have not had anybody use it with services that are not interfaces, but I would not mind adding support for that. Obviously in that case I cannot support that null object pattern "automatically" anymore (automatically meaning me creating a proxy that does nothing) but I could:
a) let the user supply some kind of factory method to supply a proxy
b) add an option to completely turn off the creation of null objects
c) anything reasonably that's suggested here :)

Greetings, Marcel


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to