当前位置: 首页>>代码示例>>Scala>>正文


Scala BuiltInComponentsFromContext类代码示例

本文整理汇总了Scala中play.api.BuiltInComponentsFromContext的典型用法代码示例。如果您正苦于以下问题:Scala BuiltInComponentsFromContext类的具体用法?Scala BuiltInComponentsFromContext怎么用?Scala BuiltInComponentsFromContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BuiltInComponentsFromContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: 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
    }
  }
} 
开发者ID:shinhwagk,项目名称:cmsfs,代码行数:53,代码来源:Loader.scala

示例2: 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)) }
} 
开发者ID:joesan,项目名称:monix-samples,代码行数:55,代码来源:MyApplicationLoader.scala

示例3: 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)
} 
开发者ID:openada,项目名称:adaweather,代码行数:41,代码来源:Boot.scala

示例4: 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))
} 
开发者ID:lunatech-labs,项目名称:teahub,代码行数:37,代码来源:AppLoader.scala

示例5: 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

} 
开发者ID:EVENFinancial,项目名称:play-compile-time-di-example,代码行数:43,代码来源:Application.scala

示例6: WebGateway

//设置package包名称以及导入依赖的类
import com.example.auction.bidding.api.BiddingService
import com.example.auction.item.api.ItemService
import com.example.auction.user.api.UserService
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 com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents
import controllers.{ Assets, ItemController, Main, ProfileController }
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 userService = serviceClient.implement[UserService]
  lazy val itemService = serviceClient.implement[ItemService]
  lazy val biddingService = serviceClient.implement[BiddingService]

  lazy val main = wire[Main]
  lazy val itemController = wire[ItemController]
  lazy val profileController = wire[ProfileController]
  lazy val assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = context.environment.mode match {
    case Mode.Dev =>
      (new WebGateway(context) with LagomDevModeComponents).application
    case _ =>
      (new WebGateway(context) with ConductRApplicationComponents).application
  }
} 
开发者ID:lagom,项目名称:online-auction-scala,代码行数:54,代码来源:Loader.scala

示例7: Loader

//设置package包名称以及导入依赖的类
package com.thoughtworks.microbuilder.tutorial.organizationBff

import com.thoughtworks.microbuilder.play.{RpcEntry, PlayOutgoingJsonService, RpcController}
import com.thoughtworks.microbuilder.tutorial.githubSdk.proxy.MicrobuilderOutgoingProxyFactory._
import com.thoughtworks.microbuilder.tutorial.githubSdk.proxy.MicrobuilderRouteConfigurationFactory._
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.proxy.MicrobuilderIncomingProxyFactory._
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.proxy.MicrobuilderRouteConfigurationFactory._
import com.thoughtworks.microbuilder.tutorial.githubSdk.rpc.IOrganizationService
import com.thoughtworks.microbuilder.tutorial.organizationBffSdk.rpc.IOrganizationBffService
import play.api.libs.ws.ning.NingWSComponents
import play.api.{BuiltInComponentsFromContext, Application, ApplicationLoader}
import play.api.ApplicationLoader.Context
import router.Routes


class Loader extends ApplicationLoader {
  override def load(context: Context): Application = {

    val components = new BuiltInComponentsFromContext(context) with NingWSComponents {
      implicit def executionContext = actorSystem.dispatcher

      lazy val organizationService = PlayOutgoingJsonService.newProxy[IOrganizationService]("https://api.github.com/", wsApi)

      lazy val bffService = new OrganizationBffService(organizationService)

      lazy val rpcController = new RpcController(Seq(RpcEntry.implementedBy[IOrganizationBffService](bffService)))

      override lazy val router = new Routes(httpErrorHandler, rpcController)
    }

    components.application
  }
} 
开发者ID:Atry,项目名称:organization-bff,代码行数:34,代码来源:Loader.scala

示例8: GrimeyAppLoader

//设置package包名称以及导入依赖的类
package com.grimey

import com.grimey.staticpage.StaticPageService
import controllers.{AdminController, HomeController, Assets, StaticPageController}

import play.api.ApplicationLoader.Context
import play.api.routing.Router
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import router.Routes
import play.api.i18n.{DefaultMessagesApi, DefaultLangs, MessagesApi, I18nSupport}
import play.api.Play.current

import scala.concurrent.Future
import scala.concurrent.duration.Duration

class GrimeyAppLoader extends ApplicationLoader {
  override def load(context: Context): Application = new GrimeyAppComponents(context).application
}

class GrimeyAppComponents(context: Context) extends BuiltInComponentsFromContext(context) with I18nSupport {
  val config = current.configuration // Todo: Inject this.

  lazy val db = new GrimeyDatabaseContext(DatabaseContextConfig(
    Duration(config.getString("grimey.db.defaultTimeoutInMs").getOrElse("10000")))).db

  lazy val staticPageService = new StaticPageService(db)

  lazy val homeController = new HomeController()
  lazy val adminController = new AdminController()
  lazy val staticPageController = new StaticPageController(staticPageService, messagesApi())
  lazy val assetsController = new Assets(httpErrorHandler)

  applicationLifecycle.addStopHook(() => Future.successful(db.close()))

  override def router: Router = new Routes(httpErrorHandler, homeController, adminController, staticPageController,
    assetsController)

  override def messagesApi(): MessagesApi = new DefaultMessagesApi(environment, configuration, new DefaultLangs(configuration))
}

case class DatabaseContextConfig(defaultTimeout: Duration) 
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:42,代码来源:GrimeyAppLoader.scala

示例9: WebGateway

//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.ApplicationLoader.Context
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import router.Routes
import com.softwaremill.macwire._
import controllers.Assets
import uk.co.turingatemyhamster.shoppinglist.user.api.UserService

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-ui",
    Map(
      "web-ui" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )

  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher

  protected implicit lazy val playConfig = context.initialConfiguration
  protected implicit lazy val playEnv = context.environment

  override lazy val router: Routes = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val userService = serviceClient.implement[UserService]

  lazy val cApplication: controllers.Application = wire[controllers.Application]
  lazy val assets: Assets = wire[Assets]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = context.environment.mode match {
    case Mode.Dev =>
      new WebGateway(context) with LagomDevModeComponents {}.application
    case _ =>
      new WebGateway(context) {
        override def serviceLocator = NoServiceLocator
      }.application
  }
} 
开发者ID:drdozer,项目名称:shoppinglist,代码行数:55,代码来源:Loader.scala

示例10: MyComponents

//设置package包名称以及导入依赖的类
package com.svitovyda

import akka.actor.ActorSystem
import com.svitovyda.configuration.ConfigurationsComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext}
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import com.svitovyda.counter.CounterComponents
import com.svitovyda.router.RouterComponents


class MyComponents(context: Context) {
  import MyComponents._

  lazy val counter = new CounterComponents

  lazy val configurations = new ConfigurationsComponents

  lazy val router = new RouterComponents(counter, configurations)

  lazy val play = new Play(context, () => router.router)
}
object MyComponents {

  val actorSystem = ActorSystem()

  class Play(
      context: ApplicationLoader.Context,
      createRouter: () => Router)
    extends BuiltInComponentsFromContext(context) {

    lazy val router: Router = createRouter()
    override lazy val actorSystem: ActorSystem = MyComponents.actorSystem
  }
} 
开发者ID:svitovyda,项目名称:scala-play254,代码行数:36,代码来源:MyComponents.scala

示例11: MockedApplicationLoader

//设置package包名称以及导入依赖的类
import akka.NotUsed
import akka.stream.scaladsl.Flow
import dao.EventDao
import models.{OrderPlaced, UserRecognized}
import play.api.{Application, BuiltInComponentsFromContext}
import play.api.ApplicationLoader.Context
class MockedApplicationLoader
    extends ConferenceManagerApplicationLoader {
  override def load(context: Context): Application =
    new BuiltInComponentsFromContext(context)
    with ConferenceManagerComponents {
      override lazy val orderDao: EventDao[OrderPlaced] =
        new EventDao[OrderPlaced]() {
          override protected def eventStore
            : Flow[String, String, NotUsed] = Flow[String]
        }
      override lazy val userDao: EventDao[UserRecognized] =
        new EventDao[UserRecognized]() {
          override protected def eventStore
            : Flow[String, String, NotUsed] = Flow[String]
        }
    }.application
} 
开发者ID:leanovate,项目名称:contoso-conference-manager,代码行数:24,代码来源:MockedApplicationLoader.scala

示例12: FakeSilhouetteMacwireComponents

//设置package包名称以及导入依赖的类
package com.github.jacobono.testkit

import controllers.{ Assets, WebJarAssets }

import play.api.BuiltInComponentsFromContext
import play.api.ApplicationLoader.Context
import play.api.cache.EhCacheComponents
import play.api.db.slick.SlickComponents
import play.api.i18n.I18nComponents
import play.api.libs.openid.OpenIDComponents
import play.api.routing.Router
import play.filters.csrf.CSRFComponents
import play.filters.headers.SecurityHeadersComponents
import router.Routes

import com.softwaremill.macwire._
import com.github.jacobono.modules._

class FakeSilhouetteMacwireComponents(context: Context) extends BuiltInComponentsFromContext(context)
    with ControllerModule with UtilModule with UserModule with SilhouetteModule with DAOModule with DatabaseModule
    with MockWsClient with I18nComponents with CSRFComponents with SecurityHeadersComponents
    with SlickComponents with EhCacheComponents with OpenIDComponents {
  lazy val routerOption = None
  override lazy val httpErrorHandler: play.api.http.HttpErrorHandler = errorHandler
  override lazy val httpFilters = filters.filters
  lazy val webJarAssets: WebJarAssets = wire[WebJarAssets]
  lazy val assets: Assets = wire[Assets]
  lazy val router: Router = {
    lazy val prefix = "/"
    wire[Routes]
  }
} 
开发者ID:jacobono,项目名称:silhouette-macwire,代码行数:33,代码来源:FakeSilhouetteMacwireComponents.scala

示例13: Frontend

//设置package包名称以及导入依赖的类
import be.yannickdeturck.lagomshopscala.item.api.ItemService
import be.yannickdeturck.lagomshopscala.order.api.OrderService
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo, ServiceLocator}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.internal.client.CircuitBreakerMetricsProviderImpl
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaClientComponents
import com.softwaremill.macwire._
import controllers.{Assets, DashboardController, ItemController, OrderController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes

import scala.collection.immutable
import scala.concurrent.ExecutionContext


abstract class Frontend(context: Context) extends BuiltInComponentsFromContext(context)
  with I18nComponents
  with AhcWSComponents
  with LagomKafkaClientComponents
  with LagomServiceClientComponents {

  override lazy val serviceInfo: ServiceInfo = ServiceInfo(
    "frontend",
    Map(
      "frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
    )
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val itemService: ItemService = serviceClient.implement[ItemService]
  lazy val itemController: ItemController = wire[ItemController]
  lazy val orderService: OrderService = serviceClient.implement[OrderService]
  lazy val orderController: OrderController = wire[OrderController]
  lazy val dashboardController: DashboardController = wire[DashboardController]
  lazy val assets: Assets = wire[Assets]
}

class FrontendLoader extends ApplicationLoader {
  override def load(context: Context): Application = context.environment.mode match {
    case Mode.Dev =>
      (new Frontend(context) with LagomDevModeComponents).application
    case _ =>
      new Frontend(context) {
        override lazy val circuitBreakerMetricsProvider = new CircuitBreakerMetricsProviderImpl(actorSystem)

        override def serviceLocator: ServiceLocator = NoServiceLocator
      }.application
  }
} 
开发者ID:yannickdeturck,项目名称:lagom-shop-scala,代码行数:59,代码来源:Loader.scala

示例14: AppLoader

//设置package包名称以及导入依赖的类
import components.CassandraRepositoryComponents
import play.api.ApplicationLoader.Context
import play.api.routing.Router
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext}
import router.Routes

class AppLoader extends ApplicationLoader {
  override def load(context: ApplicationLoader.Context): Application =
    new AppComponents(context).application
}

class AppComponents(context: Context) extends BuiltInComponentsFromContext(context) with CassandraRepositoryComponents {

  lazy val applicationController = new controllers.Application(productsRepository)
  lazy val assets = new controllers.Assets(httpErrorHandler)

  override def router: Router = new Routes(
    httpErrorHandler,
    applicationController,
    assets
  )
} 
开发者ID:manuelkiessling,项目名称:play2-compiletime-cassandra-di,代码行数:23,代码来源:AppLoader.scala

示例15: WebGateway

//设置package包名称以及导入依赖的类
import com.example.counter.api.CounterService
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import play.api.ApplicationLoader.Context
import play.api.i18n.{I18nComponents, MessagesApi}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import controllers.{CounterController, HomeController}
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(
    "front-end",
    Map("front-end" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*")))
  )
  override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher

  implicit lazy val message: MessagesApi = messagesApi

  override lazy val router = {
    val prefix = "/"
    wire[Routes]
  }

  lazy val counterService = serviceClient.implement[CounterService]

  lazy val home = wire[HomeController]
  lazy val counter = wire[CounterController]
}

class WebGatewayLoader extends ApplicationLoader {
  override def load(context: Context) = context.environment.mode match {
    case Mode.Dev => (new WebGateway(context) with LagomDevModeComponents).application
    case _ => throw new Exception("Not ready for deployment yet.")
  }
} 
开发者ID:namelos,项目名称:lagom-spike,代码行数:43,代码来源:Loader.scala


注:本文中的play.api.BuiltInComponentsFromContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。