-
-
Notifications
You must be signed in to change notification settings - Fork 0
NeuronDIForScalaSampleApplication
Christian Schlichtherle edited this page Dec 16, 2018
·
3 revisions
The following sample application is a canonical showcase for Neuron DI For Scala. The target version is Neuron DI 6.0.0 - earlier versions will not work:
import java.util.concurrent.ThreadLocalRandom
import java.util.function.Supplier
import global.namespace.neuron.di.scala._
trait Random extends Supplier[Int]
trait ConstantRandom extends Random {
override val get: Int
}
@Neuron
trait NeuronConstantRandom extends Random {
@Caching
override def get: Int
}
// This is the common dependency:
def get = ThreadLocalRandom.current.nextInt
val supplier = wire[Supplier[Int]]
println(supplier.get)
println(supplier.get)
val random = wire[Random]
println(random.get)
println(random.get)
val constant = wire[ConstantRandom]
println(constant.get)
println(constant.get)
val neuron = wire[NeuronConstantRandom]
println(neuron.get)
println(neuron.get)