All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sandinh.akuice.ActorInject.scala Maven / Gradle / Ivy

The newest version!
package com.sandinh.akuice

import akka.actor._
import com.google.inject.Injector
import scala.reflect.ClassTag

trait ActorInject {
  protected def injector: Injector

  protected def injectActor[A <: Actor](implicit factory: ActorRefFactory, tag: ClassTag[A]): ActorRef =
    factory.actorOf(Props(classOf[ActorProducer[A]], injector, tag.runtimeClass))

  protected def injectActor[A <: Actor](name: String)(implicit factory: ActorRefFactory, tag: ClassTag[A]): ActorRef =
    factory.actorOf(Props(classOf[ActorProducer[A]], injector, tag.runtimeClass), name)

  protected def injectActor(create: => Actor)(implicit factory: ActorRefFactory): ActorRef =
    factory.actorOf(Props(create))

  protected def injectActor(create: => Actor, name: String)(implicit factory: ActorRefFactory): ActorRef =
    factory.actorOf(Props(create), name)

  protected def injectTopActor[A <: Actor](implicit tag: ClassTag[A]): ActorRef =
    injector.getInstance(classOf[ActorSystem]).actorOf(Props(classOf[ActorProducer[A]], injector, tag.runtimeClass))

  protected def injectTopActor[A <: Actor](name: String)(implicit tag: ClassTag[A]): ActorRef =
    injector.getInstance(classOf[ActorSystem]).actorOf(Props(classOf[ActorProducer[A]], injector, tag.runtimeClass), name)
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy