Skip to content

NicolaeNMV/play-slick-compile-time-di-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Play Slick compile time dependency injection sample

I spent some time trying to create an project using playframework 2.4 and play-slick module with compile time DI.

So I translated the play-slick di sample to use compile time di.

The sample features:

  • Evolutions by mixing with SlickComponents with SlickEvolutionsComponents with EvolutionsComponents into ApplicationComponents and initializing evolutions when the app starts.
class ApplicationComponents(context: Context) extends BuiltInComponentsFromContext(context)
  with SlickComponents with SlickEvolutionsComponents with EvolutionsComponents {
...
  // This is required by EvolutionsComponents
  lazy val dynamicEvolutions: DynamicEvolutions = new DynamicEvolutions

  def onStart() = {
    // applicationEvolutions is a val and requires evaluation
    applicationEvolutions
  }

  onStart()
}
  • In memory database configuration for tests
  • Access to your your app components from tests by using a specs2 scope:
  "CatDAO" should {
    "work as expected" in new WithApplicationComponents {
      val dao: CatDAO = appComponents.catDao
      ..
    }
  }

I did a pull-request to play-slick project, but it's still to be merged.

About

Play 2.4 slick compile time dependency injection sample

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published