本文整理汇总了Scala中com.google.inject.AbstractModule类的典型用法代码示例。如果您正苦于以下问题:Scala AbstractModule类的具体用法?Scala AbstractModule怎么用?Scala AbstractModule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AbstractModule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Module
//设置package包名称以及导入依赖的类
import com.google.inject.AbstractModule
import java.time.Clock
import services.{ApplicationTimer, AtomicCounter, Counter}
class Module extends AbstractModule {
override def configure() = {
// Use the system clock as the default implementation of Clock
bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(classOf[ApplicationTimer]).asEagerSingleton()
// Set AtomicCounter as the implementation for Counter.
bind(classOf[Counter]).to(classOf[AtomicCounter])
}
}
示例2: Module
//设置package包名称以及导入依赖的类
import java.util.function.Function
import akka.actor.ActorRef
import com.google.inject.AbstractModule
import com.google.inject.name.Names
import com.google.inject.util.Providers
import controllers.{DefaultKnolxControllerComponents, KnolxControllerComponents}
import net.codingwell.scalaguice.ScalaModule
import play.libs.Akka
import schedulers.SessionsScheduler
class Module extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorRef]
.annotatedWith(Names.named("SessionsScheduler"))
.toProvider(Providers.guicify(Akka.providerOf(classOf[SessionsScheduler], "SessionsScheduler", Function.identity())))
.asEagerSingleton
bind(classOf[KnolxControllerComponents])
.to(classOf[DefaultKnolxControllerComponents])
.asEagerSingleton()
}
}
示例3: NoopTracerModule
//设置package包名称以及导入依赖的类
package di
import javax.inject.{Named, Singleton}
import com.google.inject.{AbstractModule, Provides}
import io.opentracing.{NoopTracerFactory, Tracer}
class NoopTracerModule extends AbstractModule {
def configure() = {
}
@Provides
@Singleton
@Named("backend")
def tracer(): Tracer = {
return NoopTracerFactory.create()
}
}
示例4: Module
//设置package包名称以及导入依赖的类
import javax.inject._
import com.google.inject.AbstractModule
import net.codingwell.scalaguice.ScalaModule
import play.api.{Configuration, Environment}
import jobs._
import models.daos._
import models.services._
class Module(environment: Environment, configuration: Configuration)
extends AbstractModule
with ScalaModule {
override def configure() = {
bind[UserDAO].to[UserDAOImpl]
bind[ClassroomDAO].to[ClassroomDAOImpl]
bind[UserService].to[UserServiceImpl]
bind[ClassroomService].to[ClassroomServiceImpl]
bind[Startup].asEagerSingleton()
}
}
示例5: Module
//设置package包名称以及导入依赖的类
import java.time.Clock
import com.google.inject.AbstractModule
import services.ApplicationTimer
import foo.services.{Counter, AtomicCounter}
class Module extends AbstractModule {
override def configure() = {
// Use the system clock as the default implementation of Clock
bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(classOf[ApplicationTimer]).asEagerSingleton()
// Set AtomicCounter as the implementation for Counter.
bind(classOf[Counter]).to(classOf[AtomicCounter])
}
}
示例6: CtxBasicModule
//设置package包名称以及导入依赖的类
package context.di
import javax.inject.Singleton
import com.google.inject.{AbstractModule, Provides}
import context.propagation.threadlocal.CurrentCtxLocalThread
import context.{CtxFactory, CtxFactorySpanOnly, CurrentCtx}
class CtxBasicModule extends AbstractModule {
def configure() = {
bind(classOf[CtxFactory]).to(classOf[CtxFactorySpanOnly]).asEagerSingleton()
}
@Provides
@Singleton
def currentCtx(): CurrentCtx = {
CurrentCtx.instance = CurrentCtxLocalThread.instance
CurrentCtx.instance
}
}
示例7: HawkularModule
//设置package包名称以及导入依赖的类
package di
import javax.inject.{Named, Singleton}
import com.google.inject.{AbstractModule, Provides}
import io.opentracing.Tracer
import org.hawkular.apm.api.utils.PropertyUtil
import org.hawkular.apm.client.api.recorder.BatchTraceRecorder.BatchTraceRecorderBuilder
import org.hawkular.apm.client.api.recorder.TraceRecorder
import org.hawkular.apm.client.api.recorder.BatchTraceRecorder
import org.hawkular.apm.trace.publisher.rest.client.TracePublisherRESTClient
class HawkularModule extends AbstractModule {
def configure() = {
}
//Hawkular seems to failed to load TracePublisher via ServiceLoader, so Made a explicit
@Provides
@Singleton
@Named("backend")
def traceRecorder(): TraceRecorder = {
val publisher = new TracePublisherRESTClient(
PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_USERNAME, "jdoe"),
PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_PASSWORD, "password"),
PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_URI, "http://localhost:8080")
)
val builder = new BatchTraceRecorderBuilder()
builder.withTracePublisher(publisher)
Option(PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHSIZE)).foreach { batchSize =>
builder.withBatchSize(Integer.parseInt(batchSize))
}
Option(PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHTIME)).foreach { batchTime =>
builder.withBatchTime(Integer.parseInt(batchTime))
}
Option(PropertyUtil.getProperty(PropertyUtil.HAWKULAR_APM_COLLECTOR_BATCHTHREADS)).foreach { threadPoolSize =>
builder.withBatchPoolSize(Integer.parseInt(threadPoolSize))
}
builder.withTenantId(PropertyUtil.getProperty("HAWKULAR_APM_TENANTID"))
new BatchTraceRecorder(builder)
}
@Provides
@Singleton
def tracer(traceRecorder: TraceRecorder): Tracer = {
val tracer0 = new org.hawkular.apm.client.opentracing.APMTracer(traceRecorder)
//GlobalTracer.register(tracer0)
//GlobalTracer.get()
tracer0
}
}
示例8: Module
//设置package包名称以及导入依赖的类
import com.google.inject.AbstractModule
import java.time.Clock
import services._
class Module extends AbstractModule {
override def configure() = {
// Use the system clock as the default implementation of Clock
bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(classOf[ApplicationTimer]).asEagerSingleton()
// Set AtomicCounter as the implementation for Counter.
bind(classOf[Counter]).to(classOf[AtomicCounter])
bind(classOf[AdminCredentialsService]).to(classOf[DbAdminCredentialService])
}
}
示例9: Module
//设置package包名称以及导入依赖的类
import com.google.inject.AbstractModule
import java.time.Clock
import services.{ApplicationTimer, AtomicCounter, Counter}
class Module extends AbstractModule {
override def configure() = {
// Use the system clock as the default implementation of Clock
bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(classOf[ApplicationTimer]).asEagerSingleton
// Set AtomicCounter as the implementation for Counter.
bind(classOf[Counter]).to(classOf[AtomicCounter])
}
}
示例10: SevenStepsModule
//设置package包名称以及导入依赖的类
package de.htwg.se.SevenSteps
import com.google.inject.AbstractModule
import com.google.inject.assistedinject.FactoryModuleBuilder
import de.htwg.se.SevenSteps.controller.IController
import de.htwg.se.SevenSteps.model.bag.IBag
import de.htwg.se.SevenSteps.model.fileIO.IFileIO
import de.htwg.se.SevenSteps.model.grid.{IGrid, IGridFactory}
import de.htwg.se.SevenSteps.model.player.IPlayers
import de.htwg.se.SevenSteps.model.{bag, fileIO, grid, player}
import net.codingwell.scalaguice.ScalaModule
class SevenStepsModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[IPlayers].to[player.basicImpl.Players]
bind[IBag].to[bag.basicImpl.Bag]
bind[IController].to[controller.basicImpl.Controller]
bind[IFileIO].to[fileIO.json.Json]
install(new FactoryModuleBuilder()
.implement(classOf[IGrid], classOf[grid.basicImpl.Grid])
.build(classOf[IGridFactory]))
}
}
示例11: Module
//设置package包名称以及导入依赖的类
import com.google.inject.AbstractModule
import java.time.Clock
import services._
class Module extends AbstractModule {
override def configure() = {
// Use the system clock as the default implementation of Clock
bind(classOf[Clock]).toInstance(Clock.systemDefaultZone)
// Ask Guice to create an instance of ApplicationTimer when the
// application starts.
bind(classOf[ApplicationTimer]).asEagerSingleton()
// Set AtomicCounter as the implementation for Counter.
bind(classOf[Counter]).to(classOf[AtomicCounter])
bind(classOf[BikeDataReader]).to(classOf[BikeDataReaderImpl])
}
}
示例12: Actors
//设置package包名称以及导入依赖的类
package modules
import actors.StatisticsProvider
import akka.actor.ActorSystem
import com.google.inject.{AbstractModule, Inject}
import play.api.Configuration
import play.api.libs.ws.WSClient
class Actors @Inject() (system: ActorSystem, ws: WSClient, config: Configuration) extends ApplicationActors {
system.actorOf(
props = StatisticsProvider.props.(ws, config).withDispatcher("control-aware-dispatcher"),
name = "statisticProvider"
)
}
trait ApplicationActors
class ActorsModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[ApplicationActors]).to(classOf[Actors]).asEagerSingleton
}
}
示例13: Actors
//设置package包名称以及导入依赖的类
package modules
import javax.inject._
import actors.StatisticsProvider
import akka.actor.ActorSystem
import com.google.inject.AbstractModule
class Actors @Inject()(system: ActorSystem) extends ApplicationActors {
system.actorOf(
props = StatisticsProvider.props.withDispatcher("control-aware-dispatvcher"),
name = "statisticsProvider"
)
}
trait ApplicationActors
class ActorsModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[ApplicationActors])
.to(classOf[Actors]).asEagerSingleton
}
}
示例14: GuiceSpec
//设置package包名称以及导入依赖的类
import com.google.inject.{AbstractModule, Guice}
import org.ababup1192._
import org.scalatest._
class GuiceSpec extends FlatSpec with Matchers {
"GuiceMain" should "have Singleton Instance" in {
val injector = Guice.createInjector(new AbstractModule {
override def configure(): Unit = {}
})
val singletonScope = injector.getInstance(classOf[SingletonScope])
val defaultScope = injector.getInstance(classOf[DefaultScope])
singletonScope.count should ===(1000)
defaultScope.count should ===(100)
singletonScope.count = 9999
defaultScope.count = 999
val singletonScope2 = injector.getInstance(classOf[SingletonScope])
val defaultScope2 = injector.getInstance(classOf[DefaultScope])
singletonScope2.count should ===(9999)
defaultScope2.count should ===(100)
}
}
示例15: ActorSystemProvider
//设置package包名称以及导入依赖的类
package com.franklevering.banking.infrastructure.dependencyinjection.modules
import akka.actor.ActorSystem
import com.franklevering.banking.infrastructure.dependencyinjection.extension.GuiceAkkaExtension
import com.google.inject.{AbstractModule, Inject, Injector, Provider}
import net.codingwell.scalaguice.ScalaModule
class ActorSystemProvider @Inject() (val injector:Injector) extends Provider[ActorSystem] {
override def get(): ActorSystem = {
val system = ActorSystem("banking-context")
GuiceAkkaExtension(system).initialize(injector)
system
}
}
class AkkaModule extends AbstractModule with ScalaModule {
override def configure(): Unit = {
bind[ActorSystem].toProvider[ActorSystemProvider].asEagerSingleton()
}
}