Let's start on defining an object type that requires dependency injection and that a callback has to be invoked once injection is complete:
import javax.annotation.PostConstruct;
import javax.inject.Singleton;
@Singleton // not necessary, but let's add some spice
public class MyServiceImpl
{
@Inject
private Dependency dependency;
// setter omitted for simplicity
@PostConstruct
public void init()
{
...
}
}All users have to do, is adding the PostConstructModule when creating the Injector:
import static com.google.inject.Guice.createInjector; import org.apache.onami.lifecycle.jsr250.PostConstructModule; ... Injector injector = createInjector( new PostConstructModule(), ... );