Java Code Examples for com.google.inject.Binder#bindListener()
The following examples show how to use
com.google.inject.Binder#bindListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropwizardModule.java From dropwizard-guicier with Apache License 2.0 | 6 votes |
@Override public void configure(final Binder binder) { binder.bindListener(Matchers.any(), new ProvisionListener() { @Override public <T> void onProvision(ProvisionInvocation<T> provision) { Object obj = provision.provision(); if (obj instanceof Managed) { handle((Managed) obj); } if (obj instanceof Task) { handle((Task) obj); } if (obj instanceof HealthCheck) { handle((HealthCheck) obj); } if (obj instanceof ServerLifecycleListener) { handle((ServerLifecycleListener) obj); } } }); }
Example 2
Source File: ServerLifeCycleModule.java From digdag with Apache License 2.0 | 5 votes |
@Override public void configure(Binder binder) { binder.disableCircularProxies(); binder.bindListener(Matchers.any(), new TypeListener() { @Override public <T> void hear(TypeLiteral<T> type, TypeEncounter<T> encounter) { encounter.register(new InjectionListener<T>() { @Override public void afterInjection(T obj) { ServerLifeCycleManager initialized = lifeCycleManagerRef.get(); if (initialized == null) { earlyInjected.add(obj); } else { try { initialized.manageInstance(obj); } catch (Exception e) { // really nothing we can do here throw new Error(e); } } } }); } }); }
Example 3
Source File: FieldInjectModule.java From nano-framework with Apache License 2.0 | 5 votes |
@Override public void configure(final Binder binder) { binder.bindListener(Matchers.any(), new TypeListener() { @Override public <I> void hear(final TypeLiteral<I> type, final TypeEncounter<I> encounter) { final List<Field> fields = fields(Lists.newArrayList(), type.getRawType()); fields.stream().filter(field -> field.isAnnotationPresent(FieldInject.class)).forEach(field -> { final FieldInject inject = field.getAnnotation(FieldInject.class); encounter.register(ReflectUtils.newInstance(inject.value(), field)); }); } }); }