1
1
package com .github .aselab .activerecord
2
2
3
3
import java .sql .Connection
4
- import javax .inject .Inject
4
+ import javax .inject ._
5
5
import java .util .{Locale , TimeZone }
6
6
import play .api .{Configuration , Environment }
7
7
import play .api .db .DBApi
@@ -12,7 +12,7 @@ class PlayConfig(
12
12
val schema : ActiveRecordTables ,
13
13
overrideSettings : Map [String , Any ] = Map ()
14
14
) extends ActiveRecordConfig {
15
- import PlayConfig ._
15
+ import PlayConfigProvider ._
16
16
17
17
lazy val schemaName = schema.getClass.getName.dropRight(1 )
18
18
lazy val _prefix = configuration.getOptional[String ](" schema." + schemaName).getOrElse(" activerecord" )
@@ -97,8 +97,8 @@ object PlayTranslator extends i18n.Translator {
97
97
def get (key : String , args : Any * )(implicit locale : Locale ): Option [String ] = {
98
98
implicit val lang = Lang (locale.getLanguage, locale.getCountry)
99
99
100
- if (PlayConfig .messages.messages.get(lang.code).exists(_.isDefinedAt(key))) {
101
- Some (PlayConfig .messages(key, args:_* ))
100
+ if (PlayConfigProvider .messages.messages.get(lang.code).exists(_.isDefinedAt(key))) {
101
+ Some (PlayConfigProvider .messages(key, args:_* ))
102
102
} else {
103
103
i18n.DefaultTranslator .get(key, args:_* )
104
104
}
@@ -110,17 +110,26 @@ trait PlaySupport { self: ActiveRecordTables =>
110
110
new PlayConfig (self, c)
111
111
}
112
112
113
- object PlayConfig {
114
- @ Inject
113
+ @ Singleton
114
+ class PlayConfigProvider @ Inject ()(
115
+ messages : MessagesApi ,
116
+ configuration : Configuration ,
117
+ environment : Environment ,
118
+ dbApi : DBApi
119
+ ) {
120
+ PlayConfigProvider .messages = messages
121
+ PlayConfigProvider .configuration = configuration
122
+ PlayConfigProvider .environment = environment
123
+ PlayConfigProvider .dbApi = dbApi
124
+ }
125
+
126
+ object PlayConfigProvider {
115
127
var messages : MessagesApi = _
116
128
117
- @ Inject
118
129
var configuration : Configuration = _
119
130
120
- @ Inject
121
131
var environment : Environment = _
122
132
123
- @ Inject
124
133
var dbApi : DBApi = _
125
134
126
135
def loadSchemas = configuration.getOptional[Configuration ](" schema" )
0 commit comments