本文整理汇总了Scala中play.api.ApplicationLoader.Context类的典型用法代码示例。如果您正苦于以下问题:Scala Context类的具体用法?Scala Context怎么用?Scala Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CustomApplicationLoader
//设置package包名称以及导入依赖的类
package modules
import play.api.ApplicationLoader
import play.api.Configuration
import play.api.inject._
import play.api.inject.guice._
import play.api.ApplicationLoader.Context
import com.typesafe.config.ConfigFactory
import play.api.Mode._
import play.Logger
class CustomApplicationLoader extends GuiceApplicationLoader {
override protected def builder(context: Context): GuiceApplicationBuilder = {
val builder = initialBuilder.in(context.environment).overrides(overrides(context): _*)
context.environment.mode match {
case Prod => {
// start mode
val prodConf = Configuration(ConfigFactory.load("prod.conf"))
builder.loadConfig(prodConf ++ context.initialConfiguration)
}
case Dev => {
Logger.error("*** Custom Loader DEV****")
// run mode
val devConf = Configuration(ConfigFactory.load("dev.conf"))
builder.loadConfig(devConf ++ context.initialConfiguration)
}
case Test => {
Logger.error("*** Custom Loader TEST ****")
// test mode
val testConf = Configuration(ConfigFactory.load("test.conf"))
builder.loadConfig(testConf ++ context.initialConfiguration)
}
}
}
}
示例2: MyApplicationLoader
//设置package包名称以及导入依赖的类
import dao.CroissantDAO
import jobs.GmailJob
import play.api._
import play.api.ApplicationLoader.Context
import router.Routes
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.libs.mailer._
import play.api.i18n.I18nComponents
import play.modules.reactivemongo.{ReactiveMongoApiFromContext, ReactiveMongoComponents}
import services.OauthProvider
import utils.{Mailer, Settings}
class MyApplicationLoader extends ApplicationLoader {
def load(context: Context) = {
LoggerConfigurator(context.environment.classLoader).foreach(_.configure(context.environment))
new MyComponents(context).application
}
}
class MyComponents(context: Context) extends ReactiveMongoApiFromContext(context)
with I18nComponents
with AhcWSComponents
with MailerComponents
with ReactiveMongoComponents {
implicit val ec = actorSystem.dispatcher
val settings = new Settings(configuration)
val mailer = new Mailer(settings, mailerClient)
val croissantDAO = new CroissantDAO(settings, mailer, reactiveMongoApi)
val oauthProvider = new OauthProvider(settings, wsClient)
//val gmailJob = new GmailJob(wsClient, actorSystem, settings, mailer, croissantDAO)
lazy val router = new Routes(
httpErrorHandler,
new controllers.CroissantController(settings, messagesApi, mailer, croissantDAO),
new controllers.AdminCroissantController(settings, messagesApi, mailer, croissantDAO),
new controllers.OauthController(oauthProvider),
new controllers.Assets(httpErrorHandler)
)
}
示例3: WebApp
//设置package包名称以及导入依赖的类
import org.culture.OrgId
import play.api.ApplicationLoader.Context
import play.api._
import play.api.mvc.Results._
import play.api.mvc._
import play.api.routing.Router
import play.api.routing.sird._
import wiring.Components
class WebApp extends ApplicationLoader {
private val components = new Components
import components._
def load(context: Context) =
new BuiltInComponentsFromContext(context) {
val router = Router.from {
case GET(p"/badge/${long(orgId)}.svg") =>
Action.async {
badgeBuilder.get(OrgId(orgId)).map { badge =>
Ok.chunked(badge.body).as("image/svg+xml;charset=utf-8")
}
}
}
}.application
}
示例4: AppLoader
//设置package包名称以及导入依赖的类
import models.{AuthorizeStoreCache, PendingContentStoreCache}
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.mvc.EssentialFilter
import play.api.routing.Router
import play.api._
import play.filters.gzip.GzipFilter
import router.Routes
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = {
LoggerConfigurator(context.environment.classLoader)
.foreach(_.configure(context.environment))
new AppComponents(context).application
}
}
class AppComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with EhCacheComponents {
implicit val executionContext =
play.api.libs.concurrent.Execution.Implicits.defaultContext
implicit lazy val authorizeStoreCache = AuthorizeStoreCache(
cacheApi("authorizeStore"))
implicit lazy val pendingConsentStoreCache = PendingContentStoreCache(
cacheApi("pendingConsentStore"))
implicit val config = configuration.underlying
lazy val applicationController = new controllers.Application
lazy val assets = new controllers.Assets(httpErrorHandler)
// Routes is a generated class
override def router: Router =
new Routes(httpErrorHandler, applicationController, assets)
val gzipFilter = new GzipFilter(shouldGzip = (request, response) => {
val contentType = response.header.headers.get("Content-Type")
contentType.exists(_.startsWith("text/html")) ||
request.path.endsWith("jsroutes.js")
})
override lazy val httpFilters: Seq[EssentialFilter] = Seq(gzipFilter)
}
示例5: AppLoader
//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource
import controllers.UsersController
import io.getquill._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.evolutions.Evolutions
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.api.routing.sird._
import models.{Users}
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = new BuiltInComponentsFromContext(context) with DBComponents with HikariCPComponents {
lazy val db = new H2JdbcContext[SnakeCase](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])
lazy val users = new Users(db)
lazy val usersController = new UsersController(users)
val router = Router.from {
case GET(p"/users/${long(id)}") => usersController.get(id)
case POST(p"/users") => usersController.create
case DELETE(p"/users/${long(id)}") => usersController.delete(id)
case PUT(p"/users/${long(id)}") => usersController.update(id)
}
override lazy val injector: Injector =
new SimpleInjector(NewInstanceInjector) + users + router + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + global
Evolutions.applyEvolutions(dbApi.database("default"))
}.application
}
示例6: WebGateway
//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.softwaremill.macwire._
import controllers.{Assets, Main}
import ogr.wex.cmsfs.monitor.api.MonitorService
import org.wex.cmsfs.lagom.service.discovery.Common
import org.wex.cmsfs.lagom.service.discovery.consul.ConsulServiceLocatorComponents
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents
with AhcWSComponents
with LagomServiceClientComponents {
override lazy val serviceInfo: ServiceInfo = ServiceInfo(
"web-gateway",
Map(
"web-gateway" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
)
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
override lazy val router = {
val prefix = "/"
wire[Routes]
}
lazy val monitorService = serviceClient.implement[MonitorService]
lazy val main = wire[Main]
lazy val assets = wire[Assets]
}
class WebGatewayLoader extends ApplicationLoader {
override def load(context: Context) = {
Common.loaderEnvironment(context)
println(context.environment.mode)
context.environment.mode match {
case Mode.Dev =>
new WebGateway(context) with LagomDevModeComponents {}.application
case _ =>
new WebGateway(context) with ConsulServiceLocatorComponents {}.application
}
}
}
示例7: Common
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.lagom.service.discovery
import com.lightbend.lagom.scaladsl.server.LagomApplicationContext
import play.api.ApplicationLoader.Context
import play.api.LoggerConfigurator
object Common {
def loaderEnvironment(context: LagomApplicationContext): Unit = {
val environment = context.playContext.environment
LoggerConfigurator(environment.classLoader).foreach(_.configure(environment))
}
def loaderEnvironment(context: Context): Unit = {
val environment = context.environment
LoggerConfigurator(environment.classLoader).foreach(_.configure(environment))
}
}
示例8: AppLoader
//设置package包名称以及导入依赖的类
package org.andrewconner.spot
import _root_.controllers.Assets
import com.softwaremill.macwire._
import org.andrewconner.spot.core.time.Clock
import org.andrewconner.spot.modules._
import play.api.ApplicationLoader.Context
import play.api._
import play.api.libs.ws.WSClient
import play.api.libs.ws.ahc.AhcWSClient
import play.api.routing.Router
import scala.concurrent.ExecutionContext
class AppLoader extends ApplicationLoader {
def load(context: Context) = {
(new BuiltInComponentsFromContext(context) with AppComponents).application
}
}
trait AppComponents
extends BuiltInComponents
with PlayAppModule
with DatabaseModule // Database injection
with DaoModule
with ControllerModule // Application controllers
with CmdrModule
with CredentialsModule {
implicit val ec: ExecutionContext = play.api.libs.concurrent.Execution.defaultContext // scala.concurrent.ExecutionContext.Implicits.global
implicit val clock: Clock = new Clock()
lazy val assets: Assets = wire[Assets]
val prefix: String = "/"
lazy val router: Router = wire[_root_.router.Routes].withPrefix(prefix)
implicit val wsClient: WSClient = AhcWSClient()
appShutdown.onStopAsync(wsClient.close())
}
示例9: MyApplicationLoader
//设置package包名称以及导入依赖的类
package my.samples.core
import com.typesafe.config.ConfigFactory
import com.typesafe.scalalogging.{ LazyLogging, StrictLogging }
import controllers.Assets
import play.api.{ Application, BuiltInComponentsFromContext, Configuration, _ }
import play.api.libs.ws.ahc.AhcWSComponents
import my.samples.controllers.MyApplicationController
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import router.Routes
import scala.concurrent.Future
// compile time DI for loading the play application
final class MyApplicationLoader extends ApplicationLoader with LazyLogging {
override def load(context: Context): Application = {
val configuration = Configuration(ConfigFactory.load())
val newContext = context.copy(initialConfiguration = configuration)
LoggerConfigurator(newContext.environment.classLoader)
.foreach(_.configure(newContext.environment))
new MyApp(newContext).application
}
}
class MyApp(context: Context)
extends BuiltInComponentsFromContext(context) with AhcWSComponents with StrictLogging {
implicit val s = monix.execution.Scheduler.Implicits.global
def stop(bindings: AppBindings) = {
logger.info("stopping application")
bindings.globalChannel.publishChannel.onComplete()
}
def start = {
logger.info("starting application")
AppBindings(actorSystem, materializer)
}
// 1. create the dependencies that will be injected
lazy val appBindings = start
// 2. inject the dependencies into the controllers
lazy val applicationController = new MyApplicationController(appBindings)
lazy val assets = new Assets(httpErrorHandler)
override def router: Router = new Routes(
httpErrorHandler, applicationController, assets
)
// 3. add the shutdown hook to properly dispose all connections
applicationLifecycle.addStopHook { () => Future(stop(appBindings)) }
}
示例10: AppLoader
//设置package包名称以及导入依赖的类
import java.io.Closeable
import javax.sql.DataSource
import controllers.MainController
import io.getquill._
import models.Services
import unus.db._
import unus.helpers.Conf
import unus.model.FeatureBuilder
import unus.stage.{BlockerCacher, DatabaseBackup, PatientCacher, PatientDatabase}
import org.flywaydb.play.FlywayPlayComponents
import play.api.ApplicationLoader.Context
import play.api._
import play.api.db.{DBComponents, HikariCPComponents}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.routing.Router
import play.filters.csrf._
import router.Routes
class AppLoader extends ApplicationLoader {
override def load(context: Context): Application = new BuiltInComponentsFromContext(context)
with DBComponents with HikariCPComponents with CSRFComponents
with FlywayPlayComponents with play.filters.HttpFiltersComponents with _root_.controllers.AssetsComponents {
lazy val db = new PostgresJdbcContext[PostgresEscape](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable])
lazy val services = new Services(db)
lazy val patientCacher = new PatientCacher
lazy val repo = new Repository(db)
lazy val blockerCachers = Conf.blockers.map(new BlockerCacher(repo, patientCacher.value, _))
lazy val features = Conf.features
lazy val controller = new MainController(services, repo, patientCacher, blockerCachers, features)(controllerComponents)
lazy val router: Router = new Routes(httpErrorHandler, controller)
override lazy val injector: Injector =
new SimpleInjector(NewInstanceInjector) + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + router
override lazy val httpFilters = Seq(csrfFilter)
flywayPlayInitializer
new PatientDatabase(repo, patientCacher).run()
if(services.getLabelCount == 0) {
new DatabaseBackup[Label]("Label").load()
}
if(services.getBlockedRowCount == 0) {
new DatabaseBackup[BlockedRow]("BlockedRow").load()
}
}.application
}
示例11: Boot
//设置package包名称以及导入依赖的类
package boot
import controllers.DevicesController
import play.api.ApplicationLoader.Context
import play.api.db.evolutions.EvolutionsComponents
import play.api.db.slick.evolutions.SlickEvolutionsComponents
import play.api.db.slick.{DbName, DefaultSlickApi}
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import play.filters.HttpFiltersComponents
import router.Routes
import services.DataSource
import slick.basic.DatabaseConfig
import services.DataSourceJdbc
import slick.jdbc.JdbcProfile
class Boot extends ApplicationLoader {
def load(context: Context): Application = {
val components = new BootComponents(context)
components.applicationEvolutions // Run the evolutions
components.application
}
}
class BootComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with HttpFiltersComponents
with controllers.AssetsComponents
with EvolutionsComponents
with SlickEvolutionsComponents {
override def api: DefaultSlickApi = new DefaultSlickApi(environment, configuration, applicationLifecycle)
private[this] val defaultDBName: DbName = DbName("devices")
private[this] val dbConfig: DatabaseConfig[JdbcProfile] = slickApi.dbConfig[JdbcProfile](defaultDBName)
// TODO put this into config
private[this] val dbPoolSize = 10
private[this] lazy val dataSource: DataSource = new DataSourceJdbc(dbConfig, dbPoolSize)
private[this] lazy val devicesController: DevicesController = new DevicesController(controllerComponents, dataSource)
override lazy val router: Routes = new Routes(httpErrorHandler, devicesController, assets)
}
示例12: BootstrapLoader
//设置package包名称以及导入依赖的类
import controllers.UserController
import dao.UserDao
import play.api.ApplicationLoader.Context
import play.api.db.evolutions.{DynamicEvolutions, EvolutionsComponents}
import play.api.db.slick.{DbName, DatabaseConfigProvider, SlickComponents}
import play.api.db.slick.evolutions.SlickEvolutionsComponents
import play.api.i18n.{DefaultLangs, DefaultMessagesApi, MessagesApi}
import play.api.routing.Router
import play.api._
import router._
import slick.driver.JdbcProfile
class BootstrapLoader extends ApplicationLoader {
override def load(context: Context): Application = {
Logger.configure(context.environment)
new ApplicationComponents(context).application
}
}
class ApplicationComponents(context: Context) extends BuiltInComponentsFromContext(context)
with SlickComponents with SlickEvolutionsComponents with EvolutionsComponents {
lazy val messagesApi: MessagesApi = new DefaultMessagesApi(environment, configuration, new DefaultLangs(configuration))
lazy val dbConfig = api.dbConfig[JdbcProfile](DbName("default"))
lazy val userDao = new UserDao(dbConfig)
lazy val applicationController = new controllers.Application()
lazy val assets = new controllers.Assets(httpErrorHandler)
lazy val webAssets = new controllers.WebJarAssets(httpErrorHandler, configuration, environment)
lazy val userController = new UserController(messagesApi, userDao = userDao)
override def router: Router = new Routes(
httpErrorHandler,
applicationController,
userController,
assets,
webAssets
)
// This is required by EvolutionsComponents
lazy val dynamicEvolutions = new DynamicEvolutions
def onStart() = {
// applicationEvolutions is a val and requires evolution
applicationEvolutions
}
onStart()
}
示例13: AppComponent
//设置package包名称以及导入依赖的类
import com.typesafe.config.Config
import controllers.{ OAuthGitHubController, TEAHubController, UIController }
import play.api.{ Application, ApplicationLoader, BuiltInComponentsFromContext, LoggerConfigurator }
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.libs.ws.ahc.AhcWSClient
import play.api.i18n._
import services.impl.{ ApiGitHubService, ApiOAuthGitHubService, ApiTogglService }
import scala.concurrent.{ ExecutionContext, Future }
import router.Routes
class AppComponent(context: Context)(implicit val ec: ExecutionContext) extends BuiltInComponentsFromContext(context)
with EhCacheComponents with I18nComponents {
val config: Config = context.initialConfiguration.underlying
val wsClient = AhcWSClient()
lazy val oauthGitHubService = new ApiOAuthGitHubService(config, wsClient)
lazy val oauthGitHubController = new OAuthGitHubController(oauthGitHubService)
lazy val gitHubService = new ApiGitHubService(wsClient)
lazy val togglService = new ApiTogglService(wsClient)
lazy val teahubController = new TEAHubController(togglService, gitHubService, defaultCacheApi)
lazy val assetsController = new controllers.Assets(httpErrorHandler)
lazy val uiController = new UIController(messagesApi, defaultCacheApi, teahubController)(ec)
lazy val router = new Routes(
httpErrorHandler,
oauthGitHubController,
uiController,
teahubController,
assetsController
)
applicationLifecycle.addStopHook(() => Future.successful(wsClient.close))
}
示例14: ApplicationLoader
//设置package包名称以及导入依赖的类
package init
import play.api.ApplicationLoader.Context
import play.api.{BuiltInComponentsFromContext, LoggerConfigurator}
import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector}
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.routing.Router
import clients._
import controllers._
import router.Routes
class ApplicationLoader extends play.api.ApplicationLoader {
def load(context: Context) = {
new ApplicationComponents(context)
with DefaultClientComponents
}.application
}
class ApplicationComponents(context: Context)
extends BuiltInComponentsFromContext(context)
with AhcWSComponents
{
self: ClientComponents =>
LoggerConfigurator(context.environment.classLoader).foreach { loggerConfigurator =>
loggerConfigurator.configure(context.environment)
}
lazy val router: Router = new Routes(
httpErrorHandler,
new UserController(userClient)
)
override lazy val injector: Injector = new SimpleInjector(NewInstanceInjector) +
router + crypto + httpConfiguration + wsApi + global
}
示例15: TestUserClient
//设置package包名称以及导入依赖的类
package test
import scala.concurrent.{ExecutionContext, Future}
import play.api.{ApplicationLoader, Environment}
import play.api.ApplicationLoader.Context
import clients._
import init.ApplicationComponents
import models.User
class TestUserClient(
users: (Int, User)*
) extends UserClient {
private val usersMap = Map(users:_*)
def getUser(id: Int)(implicit ec: ExecutionContext): Future[Option[User]] = {
Future.successful(usersMap.get(id))
}
}
class TestApplicationComponents(
context: Context = ApplicationLoader.createContext(Environment.simple()),
val userClient: UserClient
) extends ApplicationComponents(context)
with ClientComponents