Skip to content

Instantly share code, notes, and snippets.

@takezoe
Created April 7, 2012 16:04
Show Gist options
  • Save takezoe/2329981 to your computer and use it in GitHub Desktop.
Save takezoe/2329981 to your computer and use it in GitHub Desktop.
Simple wrapper of PicoContainer for Scala
import org.picocontainer.DefaultPicoContainer
/**
* Simple wrapper of PicoContainer for Scala.
*
* {{{
* val pico = new Pico()
* .add[Apple]
* .add[Juicer]
* .add[Peeler]
*
* val peeler = pico.get[Peeler]
* }}}
*/
class Pico {
val pico = new DefaultPicoContainer();
def add[T](implicit m: scala.reflect.Manifest[T]): Pico = {
val clazz = m.erasure.asInstanceOf[Class[Any]]
pico.addComponent(clazz)
this
}
def add(c: Any): Pico = {
pico.addComponent(c)
this
}
def get[T](implicit m: scala.reflect.Manifest[T]): T = {
val clazz = m.erasure.asInstanceOf[Class[Any]]
pico.getComponent(clazz).asInstanceOf[T]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment