hivemind-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Knut Wannheden <knut.wannhe...@gmail.com>
Subject Re: reusable dependency injection
Date Tue, 01 Mar 2005 11:29:33 GMT
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: hivemind-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-dev-help@jakarta.apache.org


Mime
View raw message