本文整理汇总了Scala中com.lightbend.lagom.scaladsl.api.ServiceLocator类的典型用法代码示例。如果您正苦于以下问题:Scala ServiceLocator类的具体用法?Scala ServiceLocator怎么用?Scala ServiceLocator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ServiceLocator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Lagomneo4jsampleLoader
//设置package包名称以及导入依赖的类
package com.inocybe.lagomneo4jsample.impl
import com.inocybe.lagomneo4jsample.api.Lagomneo4jsampleService
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
class Lagomneo4jsampleLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new Lagomneo4jsampleApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new Lagomneo4jsampleApplication(context) with LagomDevModeComponents
override def describeServices = List(
readDescriptor[Lagomneo4jsampleService]
)
}
abstract class Lagomneo4jsampleApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with AhcWSComponents {
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[Lagomneo4jsampleService].to(wire[Lagomneo4jsampleServiceImpl])
)
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = Lagomneo4jsampleSerializerRegistry
// Register the lagom-neo4j-sample persistent entity
persistentEntityRegistry.register(wire[Lagomneo4jsampleEntity])
}
示例2: HelloLoader
//设置package包名称以及导入依赖的类
package sample.helloworld.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import sample.helloworld.api.HelloService
class HelloLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new HelloApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new HelloApplication(context) with LagomDevModeComponents
}
abstract class HelloApplication(context: LagomApplicationContext) extends HelloComponents(context)
with LagomKafkaComponents
{
}
abstract class HelloComponents(context: LagomApplicationContext) extends LagomApplication(context)
with CassandraPersistenceComponents
with AhcWSComponents{
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[HelloService].to(wire[HelloServiceImpl])
)
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = HelloSerializerRegistry
// Register the Hello persistent entity
persistentEntityRegistry.register(wire[HelloEntity])
}
示例3: HelloConsumerLoader
//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server.{LagomApplication, LagomApplicationContext, LagomApplicationLoader, LagomServer}
import com.softwaremill.macwire._
import play.api.libs.ws.ahc.AhcWSComponents
import sample.helloworld.api.HelloService
import sample.helloworldconsumer.api.HelloConsumerService
import sample.helloworldconsumer.impl.repositories.MessageRepository
class HelloConsumerLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new HelloConsumerApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new HelloConsumerApplication(context) with LagomDevModeComponents
}
abstract class HelloConsumerApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with LagomKafkaComponents
with AhcWSComponents {
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[HelloConsumerService].to(wire[HelloConsumerServiceImpl])
)
//Bind the HelloService client
lazy val helloService = serviceClient.implement[HelloService]
lazy val messageRepository = wire[MessageRepository]
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = HelloConsumerSerializerRegistry
// Register the Message persistent entity
persistentEntityRegistry.register(wire[MessageEntity])
readSide.register(wire[MessageEventProcessor])
}
示例4: LagomhandsondevelopmentLoader
//设置package包名称以及导入依赖的类
package com.example.lagomhandsondevelopment.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.example.lagomhandsondevelopment.api.LagomhandsondevelopmentService
import com.softwaremill.macwire._
class LagomhandsondevelopmentLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new LagomhandsondevelopmentApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new LagomhandsondevelopmentApplication(context) with LagomDevModeComponents
override def describeServices = List(
readDescriptor[LagomhandsondevelopmentService]
)
}
abstract class LagomhandsondevelopmentApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with AhcWSComponents {
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[LagomhandsondevelopmentService].to(wire[LagomhandsondevelopmentServiceImpl])
)
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = LagomhandsondevelopmentSerializerRegistry
// Register the lagom-hands-on-development persistent entity
persistentEntityRegistry.register(wire[LagomhandsondevelopmentEntity])
}
开发者ID:negokaz,项目名称:lagom-hands-on-development.scala,代码行数:43,代码来源:LagomhandsondevelopmentLoader.scala
示例5: AccountLoader
//设置package包名称以及导入依赖的类
package org.ioreskovic.greatmaterialcontinuum.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import org.ioreskovic.greatmaterialcontinuum.api.AccountService
import org.ioreskovic.greatmaterialcontinuum.impl.ent.acc.{AccountEntity, AccountSerializerRegistry}
import play.api.libs.ws.ahc.AhcWSComponents
class AccountLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new AccountApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new AccountApplication(context) with LagomDevModeComponents
override def describeServices = List(
readDescriptor[AccountService]
)
}
abstract class AccountApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with LagomKafkaComponents
with AhcWSComponents {
// Bind the service that this server provides
override lazy val lagomServer = serverFor[AccountService](wire[AccountServiceImpl])
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = AccountSerializerRegistry
// Register the great-material-continuum persistent entity
persistentEntityRegistry.register(wire[AccountEntity])
}
示例6: HelloLoader
//设置package包名称以及导入依赖的类
package se.hultner.hello.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import se.hultner.hello.api.HelloService
import com.softwaremill.macwire._
class HelloLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new HelloApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new HelloApplication(context) with LagomDevModeComponents
override def describeServices = List(
readDescriptor[HelloService]
)
}
abstract class HelloApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with AhcWSComponents {
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[HelloService].to(wire[HelloServiceImpl])
)
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = HelloSerializerRegistry
// Register the Hello persistent entity
persistentEntityRegistry.register(wire[HelloEntity])
}
示例7: LagomshoppingLoader
//设置package包名称以及导入依赖的类
package com.example.lagomshopping.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.server._
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.libs.ws.ahc.AhcWSComponents
import com.example.lagomshopping.api.LagomshoppingService
import com.softwaremill.macwire._
class LagomshoppingLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication =
new LagomshoppingApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new LagomshoppingApplication(context) with LagomDevModeComponents
override def describeServices = List(
readDescriptor[LagomshoppingService]
)
}
abstract class LagomshoppingApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with CassandraPersistenceComponents
with AhcWSComponents {
// Bind the services that this server provides
override lazy val lagomServer = LagomServer.forServices(
bindService[LagomshoppingService].to(wire[LagomshoppingServiceImpl])
)
// Register the JSON serializer registry
override lazy val jsonSerializerRegistry = LagomshoppingSerializerRegistry
// Register the LagomShopping persistent entity
persistentEntityRegistry.register(wire[LagomshoppingEntity])
}
示例8: ServiceNameServiceLocator
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.lagom.service.discovery.name
import java.net.URI
import com.lightbend.lagom.internal.client.CircuitBreakers
import com.lightbend.lagom.scaladsl.api.Descriptor.Call
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.client.{CircuitBreakerComponents, CircuitBreakingServiceLocator}
import org.slf4j.{Logger, LoggerFactory}
import play.api.Configuration
import scala.concurrent.{ExecutionContext, Future}
trait ServiceNameServiceLocatorComponents extends CircuitBreakerComponents {
lazy val serviceLocator: ServiceLocator = new ServiceNameServiceLocator(configuration, circuitBreakers)(executionContext)
}
class ServiceNameServiceLocator(configuration: Configuration, circuitBreakers: CircuitBreakers)(implicit ec: ExecutionContext)
extends CircuitBreakingServiceLocator(circuitBreakers) {
private final val logger: Logger = LoggerFactory.getLogger(this.getClass)
private def getServicesByName(name: String): Option[URI] = {
Some(URI.create(s"http://${name}.cmsfs.org:9000"))
}
override def locate(name: String, serviceCall: Call[_, _]) = {
val uriOpt = getServicesByName(name)
logger.info(uriOpt.toString + " request............")
Future.successful(uriOpt)
}
}
示例9: ConsulServiceLocator
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.lagom.service.discovery.consul
import java.net.URI
import com.lightbend.lagom.internal.client.CircuitBreakers
import com.lightbend.lagom.scaladsl.api.Descriptor.Call
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.client.{CircuitBreakerComponents, CircuitBreakingServiceLocator}
import org.slf4j.{Logger, LoggerFactory}
import play.api.Configuration
import scala.concurrent.{ExecutionContext, Future}
trait ConsulServiceLocatorComponents extends CircuitBreakerComponents {
lazy val serviceLocator: ServiceLocator = new ConsulServiceLocator(configuration, circuitBreakers)(executionContext)
}
class ConsulServiceLocator(configuration: Configuration, circuitBreakers: CircuitBreakers)(implicit ec: ExecutionContext)
extends CircuitBreakingServiceLocator(circuitBreakers) {
private val logger: Logger = LoggerFactory.getLogger(this.getClass)
private val consulServiceExtract = new ConsulServiceExtract(configuration)
override def locate(name: String, serviceCall: Call[_, _]): Future[Option[URI]] = Future {
logger.debug(s"request Service Name: ${name}.")
consulServiceExtract.getService(name)
}
}
示例10: ServiceApplicationLoader
//设置package包名称以及导入依赖的类
package org.wex.cmsfs.config.impl
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import org.wex.cmsfs.config.api.ConfigService
import org.wex.cmsfs.lagom.service.discovery.Common
import play.api.libs.ws.ahc.AhcWSComponents
class ServiceApplicationLoader extends LagomApplicationLoader {
override def load(context: LagomApplicationContext): LagomApplication = {
Common.loaderEnvironment(context)
new ServiceApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
}
}
}
abstract class ServiceApplication(context: LagomApplicationContext)
extends LagomApplication(context)
with AhcWSComponents {
override lazy val lagomServer = LagomServer.forServices(
bindService[ConfigService].to(wire[ConfigServiceImpl])
)
}
示例11: lagomServer
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.scaladsl.broker.sqs
import com.lightbend.lagom.internal.scaladsl.broker.sqs.ScaladslRegisterTopicProducers
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.server.LagomServer
import com.lightbend.lagom.spi.persistence.OffsetStore
trait LagomSqsComponents extends LagomSqsClientComponents {
def lagomServer: LagomServer
def offsetStore: OffsetStore
def serviceLocator: ServiceLocator
override def topicPublisherName: Option[String] = super.topicPublisherName match {
case Some(other) =>
sys.error(s"Cannot provide the sqs topic factory " +
s"as the default topic publisher since a default topic publisher " +
s"has already been mixed into this cake: $other")
case None => Some("sqs")
}
// Eagerly start topic producers
new ScaladslRegisterTopicProducers(lagomServer, topicFactory, serviceInfo, actorSystem,
offsetStore, serviceLocator)(executionContext, materializer)
}
示例12: BasketApplication
//设置package包名称以及导入依赖的类
package demo.impl.basket
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents
import scala.collection.immutable.Seq
abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
with AhcWSComponents
with LagomKafkaComponents
with CassandraPersistenceComponents {
override def lagomServer: LagomServer = LagomServer.forServices {
bindService[BasketService].to(wire[BasketServiceImpl])
}
persistentEntityRegistry.register(wire[BasketEntity])
}
class BasketApplicationLoader extends LagomApplicationLoader {
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new BasketApplication(context) with LagomDevModeComponents {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
object BasketSerializerRegistry extends JsonSerializerRegistry {
import BasketEntityFormats._
override def serializers: Seq[JsonSerializer[_]] = Seq (
JsonSerializer[AddItem],
JsonSerializer[GetBasket.type],
JsonSerializer[GetTotal.type],
JsonSerializer[ClearAll.type],
JsonSerializer[BasketCleared.type],
JsonSerializer[ItemAdded],
JsonSerializer[BasketEntityState],
JsonSerializer[Basket],
JsonSerializer[OrderPlaced],
JsonSerializer[PlaceOrder.type],
JsonSerializer[Basket]
)
}
示例13: OrderApplication
//设置package包名称以及导入依赖的类
package demo.impl.order
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire.wire
import demo.api.basket.BasketService
import demo.api.order.OrderService
import play.api.libs.ws.ahc.AhcWSComponents
import scala.collection.immutable.Seq
abstract class OrderApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
with AhcWSComponents
with CassandraPersistenceComponents
with LagomKafkaComponents {
override def lagomServer: LagomServer = LagomServer.forServices {
bindService[OrderService].to(wire[OrderServiceImpl])
}
lazy val basketService: BasketService = serviceClient.implement[BasketService]
persistentEntityRegistry.register(wire[Order])
wire[BasketServiceSubscriber]
}
class OrderApplicationLoader extends LagomApplicationLoader {
override def loadDevMode(context: LagomApplicationContext): LagomApplication = {
new OrderApplication(context) with LagomDevModeComponents {
override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
}
}
override def load(context: LagomApplicationContext): LagomApplication = {
new OrderApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
override def jsonSerializerRegistry: JsonSerializerRegistry = OrderSerializerRegistry
}
}
}
object OrderSerializerRegistry extends JsonSerializerRegistry {
import OrderEntityFormats._
override def serializers: Seq[JsonSerializer[_]] = {
Seq(JsonSerializer[OrderInitialized],
JsonSerializer[OrderState],
JsonSerializer[CreateOrder],
JsonSerializer[GetOrder.type],
JsonSerializer[OrderItems])
}
}
示例14: BasketApplication
//设置package包名称以及导入依赖的类
package demo.impl.basket
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import com.softwaremill.macwire._
import demo.api.basket.{Basket, BasketService}
import play.api.libs.ws.ahc.AhcWSComponents
import scala.collection.immutable.Seq
abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
with AhcWSComponents
with LagomKafkaComponents
with CassandraPersistenceComponents {
override def lagomServer: LagomServer = LagomServer.forServices {
bindService[BasketService].to(wire[BasketServiceImpl])
}
persistentEntityRegistry.register(wire[BasketEntity])
}
class BasketApplicationLoader extends LagomApplicationLoader {
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new BasketApplication(context) with LagomDevModeComponents {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
object BasketSerializerRegistry extends JsonSerializerRegistry {
import BasketEntityFormats._
override def serializers: Seq[JsonSerializer[_]] = Seq (
JsonSerializer[AddItem],
JsonSerializer[GetBasket.type],
JsonSerializer[GetTotal.type],
JsonSerializer[ClearAll.type],
JsonSerializer[BasketCleared.type],
JsonSerializer[ItemAdded],
JsonSerializer[BasketEntityState],
JsonSerializer[Basket],
JsonSerializer[OrderPlaced],
JsonSerializer[PlaceOrder.type],
JsonSerializer[Basket]
)
}
示例15: BasketApplication
//设置package包名称以及导入依赖的类
package demo.impl.basket
import com.lightbend.lagom.scaladsl.api.ServiceLocator
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraPersistenceComponents
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import com.lightbend.lagom.scaladsl.server._
import demo.api.basket.{Basket, BasketService, Item}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import scala.collection.immutable.Seq
abstract class BasketApplication(ctx: LagomApplicationContext) extends LagomApplication(ctx)
with AhcWSComponents
with LagomKafkaComponents
with CassandraPersistenceComponents {
override def lagomServer: LagomServer = LagomServer.forServices {
bindService[BasketService].to(wire[BasketServiceImpl])
}
persistentEntityRegistry.register(wire[BasketEntity])
}
class BasketApplicationLoader extends LagomApplicationLoader {
override def loadDevMode(context: LagomApplicationContext): LagomApplication =
new BasketApplication(context) with LagomDevModeComponents {
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
override def load(context: LagomApplicationContext): LagomApplication = new BasketApplication(context) {
override def serviceLocator: ServiceLocator = NoServiceLocator
override def jsonSerializerRegistry: JsonSerializerRegistry = BasketSerializerRegistry
}
}
object BasketSerializerRegistry extends JsonSerializerRegistry {
import BasketEntityFormats._
override def serializers: Seq[JsonSerializer[_]] = Seq (
JsonSerializer[AddItem],
JsonSerializer[GetBasket.type],
JsonSerializer[GetTotal.type],
JsonSerializer[ItemAdded],
JsonSerializer[BasketEntityState],
JsonSerializer[Basket]
)
}