A typical singleton class :
import javax.inject._
@Singleton
class BurgersRepository {
// implementation goes here
}
Another class, requiring access to the first one.
import javax.inject._
class FastFoodService @Inject() (burgersRepository: BurgersRepository){
// implementation goes here
// burgersRepository can be used
}
Finally a controller using the last one. Note since we didn't mark the FastFoodService as a singleton, a new instance of it is created each time it is injected.
import javax.inject._
import play.api.mvc._
@Singleton
class EatingController @Inject() (fastFoodService: FastFoodService) extends Controller {
// implementation goes here
// fastFoodService can be used
}