summaryrefslogtreecommitdiffstats
path: root/sangria-contextual/src/main/java/com/tavianator
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2014-10-04 12:52:32 -0400
committerTavian Barnes <tavianator@tavianator.com>2014-10-04 12:52:32 -0400
commit3fd5777a58f59218e3229c9ea11d816ecc6ae367 (patch)
tree53f937505806e010d2bc3134fa5507d0ff78d32c /sangria-contextual/src/main/java/com/tavianator
parentb0bb30831a334ff30e3e6a13790bbc324db89de5 (diff)
parent8e24a47b69f940c31ac95451b4584b95de7c8670 (diff)
downloadsangria-3fd5777a58f59218e3229c9ea11d816ecc6ae367.tar.xz
Merge branch 'test'
Diffstat (limited to 'sangria-contextual/src/main/java/com/tavianator')
-rw-r--r--sangria-contextual/src/main/java/com/tavianator/sangria/contextual/ContextSensitiveBinder.java18
1 files changed, 15 insertions, 3 deletions
diff --git a/sangria-contextual/src/main/java/com/tavianator/sangria/contextual/ContextSensitiveBinder.java b/sangria-contextual/src/main/java/com/tavianator/sangria/contextual/ContextSensitiveBinder.java
index 6d5e502..fdc1ad0 100644
--- a/sangria-contextual/src/main/java/com/tavianator/sangria/contextual/ContextSensitiveBinder.java
+++ b/sangria-contextual/src/main/java/com/tavianator/sangria/contextual/ContextSensitiveBinder.java
@@ -40,6 +40,7 @@ import com.google.inject.spi.ProviderWithExtensionVisitor;
import com.google.inject.spi.ProvisionListener;
import com.tavianator.sangria.core.DelayedError;
+import com.tavianator.sangria.core.UniqueAnnotations;
/**
* A binder for {@link ContextSensitiveProvider}s.
@@ -139,10 +140,17 @@ public class ContextSensitiveBinder {
public void toContextSensitiveProvider(Key<? extends ContextSensitiveProvider<? extends T>> key) {
error.cancel();
- binder.bind(bindingKey).toProvider(new ProviderKeyAdapter<>(key));
+ binder.bind(bindingKey).toProvider(new ProviderKeyAdapter<>(key, makeLinkedKey(key)));
binder.bindListener(new BindingMatcher(bindingKey), new Trigger(bindingKey));
}
+ private <U> Key<U> makeLinkedKey(Key<U> key) {
+ Key<U> linkedKey = Key.get(key.getTypeLiteral(), UniqueAnnotations.create());
+ binder.bind(linkedKey)
+ .to(key);
+ return linkedKey;
+ }
+
@Override
public void toContextSensitiveProvider(ContextSensitiveProvider<? extends T> provider) {
error.cancel();
@@ -190,15 +198,19 @@ public class ContextSensitiveBinder {
private static class ProviderKeyAdapter<T> extends ProviderAdapter<T> implements ContextSensitiveProviderKeyBinding<T> {
private final Key<? extends ContextSensitiveProvider<? extends T>> providerKey;
+ private final Key<? extends ContextSensitiveProvider<? extends T>> linkedKey;
private Provider<? extends ContextSensitiveProvider<? extends T>> provider;
- ProviderKeyAdapter(Key<? extends ContextSensitiveProvider<? extends T>> providerKey) {
+ ProviderKeyAdapter(
+ Key<? extends ContextSensitiveProvider<? extends T>> providerKey,
+ Key<? extends ContextSensitiveProvider<? extends T>> linkedKey) {
this.providerKey = providerKey;
+ this.linkedKey = linkedKey;
}
@Inject
void inject(Injector injector) {
- provider = injector.getProvider(providerKey);
+ provider = injector.getProvider(linkedKey);
}
@Override