Spork Inject is a fast runtime dependency injection framework for Java/Android and is modeled on the JSR-330 specification.

Some advantages of Spork Inject:

  • Write less boilerplate code
  • Manage your dependencies more easily
  • Improve testability: swap or override dependencies for tests
  • No code generation, which makes the code easier to review
  • Decrease coupling between a class and its dependencies
  • Forces you to think about your class dependencies, which can lead to better application design


Add the following dependencies in build.gradle:

repositories {

dependencies {
    compile 'com.bytewelder.spork:spork-inject:4.0.0'


public class BrewModule {
    public Mug provideMug() {
        return new MugWithPrint("Input Java, output Java.");

    public Water provideWater() {
        return new BoilingWater();

    public Beans provideBeans() {
        return new ArabicaBeans();

    public Coffee provideCoffee(Water water, CoffeeBeans beans) {
        return new BlackCoffee(water, beans);

class CoffeeMug {
    @Inject private Coffee coffee;
    @Inject private Mug mug;

    public CoffeeMug() {
            .module(new BrewModule())
            .inject(this); // same as Spork.inject(this, objectGraph)