DInject

DInject is a dependency injection library that uses APT to generate the dependency injection as source code. It does this so that it can be very fast avoiding any use of classpath scanning, reflection and dynamic properties.

DInject is like Dagger but orientated for server side development with similar features to Spring like lifecycle support, configuration beans etc.

Example 1

Example provider implementation using DatabaseConfig and DatabaseFactory.

import io.ebean.DB;
import io.ebean.Database;
import javax.inject.Provider;

public class DatabaseProvider implements Provider<Database> {

  @Override
  public Database get() {

    DatabaseConfig config = new DatabaseConfig();
    ...
    // plus any programmatic configuration

    return DatabaseFactory.create(config);
  }
}

Inject and ActiveRecord

As long as DatabaseConfig.setRegister(true) and DatabaseConfig.setDefaultServer(true) are used in the Guice provider then the Database instance created is also available via the DB singleton and that means both @Inject and the active record style can be used.

Edit Page