本文整理了Java中play.Application.injector()
方法的一些代码示例,展示了Application.injector()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Application.injector()
方法的具体详情如下:
包路径:play.Application
类名称:Application
方法名:injector
[英]Get the runtime injector for this application. In a runtime dependency injection based application, this can be used to obtain components as bound by the DI framework.
[中]获取此应用程序的运行时注入器。在基于运行时依赖项注入的应用程序中,这可用于获取DI框架绑定的组件。
代码示例来源:origin: com.typesafe.play/play-test_2.12
/**
* Provides an instance from the application.
*
* @param clazz the type's class.
* @param <T> the type to return, using `app.injector.instanceOf`
* @return an instance of type T.
*/
protected <T> T instanceOf(Class<T> clazz) {
return app.injector().instanceOf(clazz);
}
代码示例来源:origin: com.typesafe.play/play-test_2.11
/**
* Provides an instance from the application.
*
* @param clazz the type's class.
* @param <T> the type to return, using `app.injector.instanceOf`
* @return an instance of type T.
*/
protected <T> T instanceOf(Class<T> clazz) {
return app.injector().instanceOf(clazz);
}
代码示例来源:origin: com.typesafe.play/play-test_2.10
@SuppressWarnings(value = "unchecked")
private static Result invokeHandler(play.api.mvc.Handler handler, Request requestBuilder, long timeout) {
if (handler instanceof play.api.mvc.Action) {
play.api.mvc.Action action = (play.api.mvc.Action) handler;
return wrapScalaResult(action.apply(requestBuilder._underlyingRequest()), timeout);
} else if (handler instanceof JavaHandler) {
return invokeHandler(
((JavaHandler) handler).withComponents(Play.application().injector().instanceOf(JavaHandlerComponents.class)),
requestBuilder, timeout
);
} else {
throw new RuntimeException("This is not a JavaAction and can't be invoked this way.");
}
}
代码示例来源:origin: com.typesafe.play/play
/**
* Retrieve Lang availables from the application configuration.
*
* @param app the current application.
* @return the list of available Lang.
*/
public static List<Lang> availables(Application app) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables());
return availableLangs.stream().map(Lang::new).collect(toList());
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Retrieve Lang availables from the application configuration.
*
* @param app the current application.
* @return the list of available Lang.
*/
public static List<Lang> availables(Application app) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables());
return availableLangs.stream().map(Lang::new).collect(toList());
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Retrieve Lang availables from the application configuration.
*
* @param app the current application.
* @return the list of available Lang.
*/
public static List<Lang> availables(Application app) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
List<play.api.i18n.Lang> availableLangs = Scala.asJava(langs.availables());
return availableLangs.stream().map(Lang::new).collect(toList());
}
代码示例来源:origin: com.typesafe.play/play_2.10
private static MessagesApi getMessagesApi() {
return play.Play.application().injector().instanceOf(MessagesApi.class);
}
代码示例来源:origin: com.typesafe.play/play
/**
* Guess the preferred lang in the langs set passed as argument.
* The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application.
*
* @param app the currept application
* @param availableLangs the set of langs from which to guess the preferred
* @return the preferred lang.
*/
public static Lang preferred(Application app, List<Lang> availableLangs) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
Stream<Lang> stream = availableLangs.stream();
List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList());
return new Lang(langs.preferred(Scala.toSeq(langSeq)));
}
}
代码示例来源:origin: com.typesafe.play/play_2.11
/**
* Guess the preferred lang in the langs set passed as argument.
* The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application.
*
* @param app the currept application
* @param availableLangs the set of langs from which to guess the preferred
* @return the preferred lang.
*/
public static Lang preferred(Application app, List<Lang> availableLangs) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
Stream<Lang> stream = availableLangs.stream();
List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList());
return new Lang(langs.preferred(Scala.toSeq(langSeq)));
}
}
代码示例来源:origin: com.typesafe.play/play_2.12
/**
* Guess the preferred lang in the langs set passed as argument.
* The first Lang that matches an available Lang wins, otherwise returns the first Lang available in this application.
*
* @param app the currept application
* @param availableLangs the set of langs from which to guess the preferred
* @return the preferred lang.
*/
public static Lang preferred(Application app, List<Lang> availableLangs) {
play.api.i18n.Langs langs = app.injector().instanceOf(play.api.i18n.Langs.class);
Stream<Lang> stream = availableLangs.stream();
List<play.api.i18n.Lang> langSeq = stream.map(l -> new play.api.i18n.Lang(l.toLocale())).collect(toList());
return new Lang(langs.preferred(Scala.toSeq(langSeq)));
}
}
代码示例来源:origin: com.typesafe.play/play_2.10
/**
* @return the messages for the current lang
*/
public Messages messages() {
return Play.application().injector().instanceOf(MessagesApi.class).preferred(request());
}
代码示例来源:origin: com.github.rmannibucau/playx-ioc
IoCApplication(final Map<ApplicationLoader, Application> values, final Map<String, String> routing) {
this.delegates = new ArrayList<>(values.values());
this.injector = new IoCInjector(
values.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue().injector(), (a, b) -> {
throw new IllegalStateException("Conflicting keys for " + a + "/" + b);
}, LinkedHashMap::new)), routing);
this.scalaRef = delegates.iterator().next().asScala();
this.java = new DefaultApplication(this, injector.asJava());
playxIntegration();
}
代码示例来源:origin: com.typesafe.play/play-java-jpa_2.10
/**
* Get the JPA api for the current play application.
*/
public static JPAApi jpaApi() {
Application app = Play.application();
if (app == null) {
throw new RuntimeException("No application running");
}
return app.injector().instanceOf(JPAApi.class);
}
内容来源于网络,如有侵权,请联系作者删除!