【发布时间】:2016-04-28 06:19:36
【问题描述】:
在将应用程序从 2.4 迁移到 2.5(并摆脱所有静态引用)的过程中,我做了以下事情:
class Generic @Inject()(implicit val mat: Materializer, cache: CacheApi, wsClient: WSClient, configuration: play.api.Configuration)
{ ... }
@Singleton
class Concrete1 @Inject() (gw:Generic) { ... }
@Singleton
class Concrete2 @Inject() (gw:Generic) { ... }
要使用它,我会使用 Generic 实例注入 Concrete1/2。 它有效,但在网上看到其他几个关于此的示例后,它似乎不太正确。
我正在考虑这样修改它:
abstract class Generic(cache: CacheApi, wsClient: WSClient, configuration: play.api.Configuration)
{ ... }
@Singleton
class Concrete1(cache: CacheApi, wsClient: WSClient, configuration: play.api.Configuration)
extends Generic(cache, wsClient, configuration) { ... }
@Singleton
class Concrete2(cache: CacheApi, wsClient: WSClient, configuration: play.api.Configuration)
extends Generic(cache, wsClient, configuration) { ... }
那么为了能够做到:@Inject() (c1:Concrete1, c2:Concrete2)
我想我需要它们成为由 https://www.playframework.com/documentation/2.5.x/ScalaDependencyInjection#Programmatic-bindings 定义的模块?
在这里做什么更有意义?
【问题讨论】:
标签: scala playframework playframework-2.5