<xweld/>-inject

With an implementation less than 1500 lines of code, <xweld/>-inject is an container-free, ultra-lightweight dependency injection framework for J2SE and J2EE applications that is compatible with the JSR-330 Specification (http://jcp.org/en/jsr/detail?id=330). You can learn more about how to use the injection framework with the <xweld/> runtime module here: http://www.xweld.com/projects/xweld-runtime/wiki

Useful Reading

Primary Features and Benefits

The <xweld/> inject module supports the Java community standard JSR-330 for dependency injection. Why create yet another dependency injection framework? Two reasons:

  • The <xweld/> implementation is ultra-small, with less than 1500 lines of code in the package so the footprint for your application is miniscule and smaller than any other implementation we know of.
  • JSR-330 and all the implementations that support it do not standardize on how the framework itself is initialized and configured. The <xweld/>-inject implementation defines a common mechanism for the configuration and setup of DI for all <xweld/> applications and any other implementation may be swapped in, namely Spring, Guice or Pico for example without changing any application code.

Key Concepts

The <xweld/>-inject module starts where JSR-330 leaves off -- by providing all applications with a standard way to setup and configure the dependency injection framework, regardless of the implementation of JSR-330 underneath. As with all JSR-330 compliant implementations, you can think of the @Inject annotation as a replacement for Java's 'new' operator. Applications obtain an Injector instance from the factory method of the Inject class. The Injector instance is then used get instances of types as needed, without calling 'new'.

Static and private member injection support is optional under JSR-330, and in order to keep the implementation as concise as possible, <xweld/>-inject does not support this feature.

The IPersistenceManager is supported as an @Singleton by the framework, so if you're using the injection module, you can initialize IPersistencemanager instances in your code like this:

  class MyDAO
  {
    @Inject IPersistenceManager persistenceManager;
    // ... more class implementation
  }

Packages and Classes

xweld-inject includes the following packages:

  • com.xweld.inject – the basic classes for configuring the bindings for the injection framework into groupings called Modules.

com.xweld.inject class diagram

Runtime Components

The JSR-330 initiative, or atinject, defines a TCK test harness useful in demonstrating compatibility with the standard. The tests are found in the org.atinject.tck.auto package and the TCK is included as part of the standard build process for the <xweld/>-inject module. The example below shows how to configure and create an Injector for this test suite:

  Module module = new Module()
  {
    @Override
    public void configure()
    {
      bind(Car.class).toType(Convertible.class);
      bind(Engine.class).toType(V8Engine.class);
      bind(Tire.class).toName("spare").toType(SpareTire.class);
      bind(Seat.class).toAnnotation(Drivers.class).toType(DriversSeat.class);
    }
  };

  Injector injector = Inject.createInjector(module);
  injector.register(module);

  // use the injector 'get' method to create a new instance.

  Car car = injector.get(Car.class);

The atinjject home page may be found here http://code.google.com/p/atinject/.

Contact Us

For more information, please contact us at

Copyright

Copyright © 1999-2012 <xweld/> Development Community, All Rights Reserved.

The contents of this web site, including all images, text, graphics and software, are the sole property of the <xweld/> Development Community and its agents. Unauthorized use or transmission is strictly forbidden by international copyright law.

com.xweld.inject.JPG - com.xweld.inject class diagram (36.9 kB) John Free, 03 December 2011 01:13 PM