@Override
  public boolean bind(Class<?> component, Set<Class<?>> providerContracts) {
    if (injector != null) {
      Key<?> key = Key.get(component);
      Binding<?> binding = injector.getExistingBinding(key);

      // Does the constructor require Guice Binding?
      if (binding == null) {
        binding = injector.getBinding(key);
      }

      DynamicConfiguration c = Injections.getConfiguration(locator);
      ServiceBindingBuilder bb =
          Injections.newFactoryBinder(new GuiceBindingComponentFactory(binding));
      bb.to(component);
      Injections.addBinding(bb, c);
      c.commit();
      return true;
    }

    return false;
  }
Esempio n. 2
0
  @Override
  public void close() {
    if (isClosed()) {
      throw new ClosedInjectorException(this);
    }

    for (Key<?> key : delegate.getAllBindings().keySet()) {
      try {
        com.google.inject.Binding<?> binding = delegate.getExistingBinding(key);
        if (!Scopes.isSingleton(binding)) {
          continue;
        }
        invokeAnnotatedMethod(binding.getProvider().get(), PreDestroy.class);
      } catch (ProvisionException pe) {
        if (!(pe.getCause() instanceof TypeNotFoundException)) {
          pe.printStackTrace();
        }
      }
    }

    synchronized (lock) {
      closed = true;
    }
  }