Hi again,

I have pushed on with the implementation of an interface to dependency
injection. It's not that easy to come up with something powerful and
reasonably simple to understand and use. Anyway here is what I now
have:

public class DependencyInjector
{
  // Returns an instance of 'clazz' by using the longest constructor 
  // satisfying 'spec'.
  public Object createInstance(Class clazz, ConstructorSpecification spec) {...}

  // Injects all properties defined by 'specs' into 'object'. First injects all
  // required properties and then injects any unassigned optional properties.
  public void injectProperties(Object object, PropertySpecification[]
specs) {...}
}

public interface ConstructorSpecification
{
  // Determines whether the given constructor 'c' satisfies this specification.
  public boolean isSatisfiedBy(Constructor c);

  // Returns the constructor parameters for a satisfying constructor 'c'.
  public Object[] getConstructorParameters(Constructor c);
}

public interface PropertySpecification
{
  // Returns all properties required by this specification when
  // injecting into 'object'.
  public List getRequiredProperties(Object object);

  // Returns all properties which are optional when
  // injecting into 'object'.
  public List getOptionalProperties(Object object);

  // Returns the value for 'property' (required or optional)
  // when injecting into 'object'.
  public Object getPropertyValue(Object object, String property);
}

Does this breakup make sense? The next thing I want to look at is
supporting initializer methods and injecting event listeners.

Note that I've also written some implementations to these interfaces
and I have successfully integrated this code into the BuilderFactory.

--knut

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

Reply via email to