Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 性状混合蛋白中的sphiti注射剂_Scala_Implicit_Scaldi - Fatal编程技术网

Scala 性状混合蛋白中的sphiti注射剂

Scala 性状混合蛋白中的sphiti注射剂,scala,implicit,scaldi,Scala,Implicit,Scaldi,在SHOTHI中,类可以有隐式inj:Injector,并且在SHOTHI模块中定义时,Injector在无任何附加代码的情况下传递 class MessageService(implicit inj: Injector) extends Injectable { val officialGreeting = inject [String] (identified by "greeting.official") def getGreet

在SHOTHI中,类可以有
隐式inj:Injector
,并且在SHOTHI
模块中定义时,
Injector
在无任何附加代码的情况下传递

class MessageService(implicit inj: Injector)
          extends Injectable {

  val officialGreeting =
    inject [String] (identified by "greeting.official")

  def getGreetMessage(name: String) =
    s"$officialGreeting, $name!"
}

//Module
class UserModule extends Module {
  bind [MessageService] to new MessageService

  binding identifiedBy "greeting.official" to "Welcome"
}
如何做到同样,但在一个特点

class MessageService() {

  val officialGreeting =
    inject [String] (identified by "greeting.official")

  def getGreetMessage(name: String) =
    s"$officialGreeting, $name!"
}

trait MessageServiceReportingMixin extends MessageService with Injectable {

  implicit val inj: Injector 

  val reporter = inject[Reporter]

  override def getGreetMessage(name: String) = reporter.report(super.getGreetMessage(name))
}

//Module
class UserModule extends Module {

  //I WANT TO AVOID THIS
  bind [MessageService] to new MessageService() with MessageServiceReportingMixin {
    val inj = injector
  }

  //I WANT TO DO THIS INSTEAD
  bind [MessageService] to new MessageService() with MessageServiceReportingMixin

  binding identifiedBy "greeting.official" to "Welcome"
}
implicit val inj:Injector=implicit
是否会出现任何问题,以使其正常工作?另外,请评论将报告作为混音从主类中分离出来的总体风格