I have followed the discussion regarding how to provide
dependencies to a component - i.e. do we do it via a
ServiceManager, do we use setter methods or do we
use constructors (like MicroContainer)?
-oOo-
I has a little RT regarding how one could use attributes to
pass dependencies. Two ways:
Via Constructor
---------------
This is based on allowing attributes to be added not just to
methods and constructors, but to parameters as well.
public class MyComponent {
/**
* @@.std RequireDependencyAttribute ( "standard" )
* @@.err RequireDependencyAttribute ( "error" )
*/
public MyComponent( OutputTarget std, OutputTarget err ) { ... }
}
Then a container can get attributes for each constructor parameter
and use those to figure out what component to pass in.
(Yes, when you not only just have a hammer, but manufacture hammers,
all problems look like nails...)
Random question - are attributes inherited here?
Via Field
---------
The AccessibleObject.setAccessible method is cool. It allows you to
access private fields if the security manager says so (this is how
the serialization process can serialize private fields via reflection).
This means we can directly populate the fields of a component:
public class MyComponent {
/**
* @@Dependency
* @@RequireDependencyAttribute ( "standard" )
*/
private OutputTarget standard;
/**
* @@Dependency
* @@RequireDependencyAttribute ( "error" )
*/
private OutputTarget error;
}
A container can now get attributes for all fields (even the private
ones)
and set the dependencies just after invoking the constructor.
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]