Skip to content
converts guice modules into plain old java factories
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
src
.gitignore
LICENSE
README.md
build.smooth

README.md

deguicifier

Tool for converting guice modules into plain old java factories.
(similar to those you would write by hand).

Usage example

Suppose we have java application that is bootstrapped using guice as shown below:

import my.app.AppModule;
import my.app.App;
import com.google.inject.Injector;

public class Main {
  public static void main(String[] args) {
    Injector injector = Guice.createInjector(new AppModule());
    App app = injector.getInstance(App.class);
    app.start();
  }
}

We can use deguicifier to generate wiring code so we could bootstrap our app without using guice. To generate mentioned code run:

java -cp deguicifier-0.2.0.jar:guice-3.0.jar:javax.inject.jar:app.jar \
  com.perunlabs.deguicifier.Main \
  my.app.AppModule \
  my.app.App \
  my.app.AppFactory \
  >> my/app/AppFactory.java

This will generate AppFactory java class. You can use it to bootstrap your app without guice:

import my.app.App;
import my.app.AppFactory;
import javax.inject.Provider;

public class Main {
  public static void main(String[] args) {
    Provider<App> appProvider = new AppFactory();
    App app = appProvider.get();
    app.start();
  }
}

Guice features that are not supported

  • binding to instance (except binding to primitive types, their wrappers, Strings)
  • binding to provider instance
  • binding as eager singleton
  • using MapBinder (Multibindings are supported)
  • circular dependencies
  • field injections
  • binding Scope instance which class cannot be easily instantiated - It is either not public, have no public constructor or have generic parameters (simply put it's not possible to generate code that instantiate such class).
You can’t perform that action at this time.