/** * Qualify this binding key with the given instance of an annotation. * * This can be used to specify bindings with annotations that have particular values. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final A instance) { return underlying.qualifiedWith(instance).asJava(); }
/** * Qualify this binding key with the given instance of an annotation. * * This can be used to specify bindings with annotations that have particular values. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final A instance) { return underlying.qualifiedWith(instance).asJava(); }
/** * Qualify this binding key with the given instance of an annotation. * * This can be used to specify bindings with annotations that have particular values. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final A instance) { return underlying.qualifiedWith(instance).asJava(); }
/** * Qualify this binding key with the given name. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may decide to name the cached one: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith("cached").to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Named("cached") Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached `Foo` service. */ public BindingKey<T> qualifiedWith(final String name) { return underlying.qualifiedWith(name).asJava(); }
/** * Qualify this binding key with the given annotation. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may define a Cached annotation: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith(Cached.class).to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Cached Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached {@code Foo} service. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final Class<A> annotation) { return underlying.qualifiedWith(annotation).asJava(); }
/** * Qualify this binding key with the given annotation. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may define a Cached annotation: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith(Cached.class).to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Cached Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached {@code Foo} service. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final Class<A> annotation) { return underlying.qualifiedWith(annotation).asJava(); }
/** * Qualify this binding key with the given name. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may decide to name the cached one: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith("cached").to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Named("cached") Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached `Foo` service. */ public BindingKey<T> qualifiedWith(final String name) { return underlying.qualifiedWith(name).asJava(); }
/** * Qualify this binding key with the given annotation. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may define a Cached annotation: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith(Cached.class).to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Cached Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached {@code Foo} service. */ public <A extends Annotation> BindingKey<T> qualifiedWith(final Class<A> annotation) { return underlying.qualifiedWith(annotation).asJava(); }
/** * Qualify this binding key with the given name. * * For example, you may have both a cached implementation, and a direct implementation of a service. To differentiate * between them, you may decide to name the cached one: * * <pre> * {@code * bindClass(Foo.class).qualifiedWith("cached").to(FooCached.class), * bindClass(Foo.class).to(FooImpl.class) * * ... * * class MyController { * {@literal @}Inject * MyController({@literal @}Named("cached") Foo foo) { * ... * } * ... * } * } * </pre> * * In the above example, the controller will get the cached `Foo` service. */ public BindingKey<T> qualifiedWith(final String name) { return underlying.qualifiedWith(name).asJava(); }
@Override public Seq<Binding<?>> bindings(Environment environment, Configuration configuration) { String dbKey = configuration.underlying().getString("play.db.config"); String defaultDb = configuration.underlying().getString("play.db.default"); ImmutableList.Builder<Binding<?>> list = new ImmutableList.Builder<Binding<?>>(); list.add(bind(ConnectionPool.class).to(DefaultConnectionPool.class)); list.add(bind(DBApi.class).to(DefaultDBApi.class)); try { Set<String> dbs = configuration.underlying().getConfig(dbKey).root().keySet(); for (String db : dbs) { list.add(bind(Database.class).qualifiedWith(named(db)).to(new NamedDatabaseProvider(db))); } if (dbs.contains(defaultDb)) { list.add(bind(Database.class).to(bind(Database.class).qualifiedWith(named(defaultDb)))); } } catch (com.typesafe.config.ConfigException.Missing e) { // ignore missing configuration } return Scala.toSeq(list.build()); }