com.google.gerrit.lifecycle.LifecycleModule Maven / Gradle / Ivy
package com.google.gerrit.lifecycle;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.binder.LinkedBindingBuilder;
import com.google.inject.internal.UniqueAnnotations;
import java.lang.annotation.Annotation;
/** Module to support registering a unique LifecyleListener. */
public abstract class LifecycleModule extends AbstractModule {
/**
* Create a unique listener binding.
*
* To create a listener binding use:
*
*
* listener().to(MyListener.class);
*
*
* where {@code MyListener} is a {@link Singleton} implementing the
* {@link LifecycleListener} interface.
*/
protected LinkedBindingBuilder listener() {
final Annotation id = UniqueAnnotations.create();
return bind(LifecycleListener.class).annotatedWith(id);
}
}