// get created in this example
List<Class<?>> ignore = Lists.newArrayList();
ignore.add(ExampleService.class);
// Always get the Guice injector from Governator
Injector injector = LifecycleInjector
.builder()
.usingBasePackages("autobind")
.ignoringAutoBindClasses(ignore) // tell Governator's CLASSPATH scanner to ignore listed classes
.withBootstrapModule
(
new BootstrapModule()
{
@Override
public void configure(BootstrapBinder binder)
{
// bind an AutoBindProvider for @AutoBind annotated fields/arguments
TypeLiteral<AutoBindProvider<AutoBind>> typeLiteral = new TypeLiteral<AutoBindProvider<AutoBind>>(){};
binder.bind(typeLiteral).to(ExampleAutoBindProvider.class).asEagerSingleton();
}
}
)
.createInjector();
LifecycleManager manager = injector.getInstance(LifecycleManager.class);
// Always start the Lifecycle Manager
manager.start();
System.out.println(injector.getInstance(ExampleObjectA.class).getValue());
System.out.println(injector.getInstance(ExampleObjectB.class).getValue());
System.out.println(injector.getInstance(ExampleObjectC.class).getValue());
/*
Console will output:
letter A - 1
letter B - 2