use of com.google.inject.spi.DefaultBindingScopingVisitor in project ninja by ninjaframework.
the class LifecycleServiceImpl method start.
@Override
public void start() {
startTime = System.currentTimeMillis();
log.info("Starting Ninja application...");
state = State.STARTING;
// until they are instantiated that LifecycleSupport has an opportunity to register them.
for (final Binding binding : injector.getBindings().values()) {
binding.acceptScopingVisitor(new DefaultBindingScopingVisitor() {
@Override
public Object visitEagerSingleton() {
injector.getInstance(binding.getKey());
return null;
}
@Override
public Object visitScope(Scope scope) {
if (scope.equals(Scopes.SINGLETON)) {
Object target = injector.getInstance(binding.getKey());
if (binding instanceof ProviderInstanceBinding) {
Provider providerInstance = ((ProviderInstanceBinding) binding).getProviderInstance();
if (providerInstance instanceof ProviderMethod) {
// @Provides methods don't get picked up by TypeListeners, so we need to manually register them
if (lifecycleSupport.hasLifecycleMethod(target.getClass())) {
lifecycleSupport.registerLifecycle(target);
}
}
}
}
return null;
}
});
}
lifecycleRegister.start();
long time = System.currentTimeMillis() - startTime;
log.info("Ninja application started in {}ms", time);
state = lifecycleRegister.isStarted() ? State.STARTED : State.STOPPED;
}
Aggregations