Skip to content

Instantly share code, notes, and snippets.

@gakuzzzz
Created July 29, 2013 03:26
Show Gist options
  • Save gakuzzzz/6101977 to your computer and use it in GitHub Desktop.
Save gakuzzzz/6101977 to your computer and use it in GitHub Desktop.
cake と cake じゃない所と
package disample
case class DiSampleConfig(foo: Int, bar: String)
object DiSampleConfig {
implicit val configs: Configs[DiSampleConfig] = Configs { c =>
DiSampleConfig(
foo = c.get[Int]("foo"),
bar = c.get[String]("bar")
)
}
}
trait DiSampleComponents {
lazy val disampleConfig: DiSampleConfig =
ConfigFactory.load("applocation.conf").get[DiSampleConfig]("disample")
}
package disample.hoge
class HogeDao {
}
class HogeService(hogeDao: HogeDao, config: DiSampleConfig) {
}
trait HogeComponents {
self: DiSampleComponents =>
lazy val hogeDao: HogeDao = new HogeDao()
lazy val hogeService: HogeService = new HogeService(hogeDao, disampleConfig)
}
package disample.piyo
class PiyoDao {
}
class PiyoService(piyoDao: PiyoDao, config: DiSampleConfig) {
}
trait PiyoComponents {
self: DiSampleComponents =>
lazy val piyoDao: PiyoDao = new PiyoDao()
lazy val piyoService: PiyoService = new PiyoService(piyoDao, disampleConfig)
}
trait ComponentRepository extends HogeComponents with PiyoComponents with DiSampleComponents
trait AAAController extends ComponentRepository {
def action = Action {
hogeService.XXX
}
}
class AAAControllerSpec with mockit {
object AAAController extends AAAController {
override lazy val hogeDao: HogeDao = mock[HogeDao]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment