Netflix/governator — pull request #154 by elandau (2014-08-26 04:59:07+00:00)
Title: Support for JDK ServiceLoader

Integrate the JDK ServiceLoader with Guice making it possible to inject a Set of services and allowing member injection on these services. Two modes will be supported.

1. Eager loading of services at startup with support for multibinding so additional bindings for services can be added outside of the ServiceLoader
2. Lazy loading of services until Set is injected but without allowing for additional bindings to be added using multibindings

Example,

Eager binding,
```java
injectorBuilder.withAdditionalModules(new ServiceLoaderModule() {
void configure() {
// Instantiate and load services of type MyService.
loadAndMultibindServices(MyService.class);
// This is legal,
Multibinder.newSetBinder(binder(), MyService.class).addBinding().to(MyServiceImpl.class);
}
});
```

Lazy binding
```java
injectorBuilder.withAdditionalModules(new ServiceLoaderModule() {
void configure() {
lazyLoadAndBindServices(MyService.class);
// This is illegal now because the above line fully implements the binding for Set
// Multibinder.newSetBinder(binder(), MyService.class).addBinding().to(MyServiceImpl.class);
}
});
```

Injecting
```java
public class SomeApplicationClass {
@Inject
public SomeApplicationClass(Set services) {

}
}
```

Example service,
```java
public class MyServiceImpl Implements MyService {
public MyServiceImpl() {
}

// This injection will be done when Set is first injected
@Inject
public voidSetSomeDependency(SomeDependency dep) {
}
}
```