On Jan 14, 2007, at 2:48 AM, Jacek Laskowski wrote:
Hi, While reviewing Raj's patch for a setter injection example I spot that the private method was used with the @Resource dependency annotation. As I've been thinking about it for a while before I saw it in Raj's patch it's a good time to ask here and find out where I was wrong. To me, using non-public methods with a dependency annotation is a bad idea. It is because it hinders component testing capability, i.e. there's no simple way to test out the component outside the container (tm), not too mention that constructing an instance is much harder with no DI env. Rather than just setting up the component via setters (when public methods are the only ones dependency annotated) with no complicated test environment, one would have to use DI framework to inject the resources and only when it finishes fine start the tests. To sum up, using non-public methods for setter injection is highly discouraged and deemed a bad practice. And no field injection should be used, either.
I agree private field setter injection is not the best idea for exactly the reasons you mention. The spec allows it so it's fine to show it, but your comments would be great to add to the examples README.txt file. Or maybe in the wiki page that needs to be created for the example.
-David
Am I missing something? Jacek -- Jacek Laskowski http://www.JacekLaskowski.pl
