本文整理汇总了Scala中com.google.inject.Inject类的典型用法代码示例。如果您正苦于以下问题:Scala Inject类的具体用法?Scala Inject怎么用?Scala Inject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Inject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: add
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import model.{Artist, ArtistDAO, Temp}
import play.api.libs.json.{JsValue, Json, Writes}
import play.api.Logger
import scala.concurrent.ExecutionContext
@ImplementedBy(classOf[ArtistServicesImpl])
trait ArtistServices {
def add (discActor : Artist) : Boolean
def findAllByType(value: String) : ArtistResponse
}
case class ArtistResponse(artists : List[Artist])
object ArtistResponse {
//implicit val formatter1 = Json.format[Artist]
implicit val formatter2 = Json.format[ArtistResponse]
Logger.debug("Attempting risky calculation.")
implicit val implicitFooWrites = new Writes[ArtistResponse] {
def writes(discActors : ArtistResponse): JsValue = {
Json.obj(
"artists" -> discActors.artists
)
}
}
}
class ArtistServicesImpl @Inject()(dao: ArtistDAO )(implicit ec: ExecutionContext) extends ArtistServices {
override def add(artist : Artist ): Boolean = {
if(dao.addNew(artist)!=null)
true
else
false
}
override def findAllByType(value: String): ArtistResponse = {
println("Find Artist by Name: " + value)
ArtistResponse(dao.getAllByName(value).filter(a => a.isDefined).map(a => a.get))
}
}
示例2: Application
//设置package包名称以及导入依赖的类
package lunatech.lunchplanner.controllers
import com.google.inject.Inject
import lunatech.lunchplanner.common.DBConnection
import lunatech.lunchplanner.models.User
import lunatech.lunchplanner.services.{ MenuPerDayPerPersonService, UserService }
import lunatech.lunchplanner.viewModels.MenuPerDayPerPersonForm
import play.api.i18n.{ I18nSupport, MessagesApi }
import play.api.mvc.{ Controller, Flash }
import play.api.{ Configuration, Environment }
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
class Application @Inject() (
userService: UserService,
menuPerDayPerPersonService: MenuPerDayPerPersonService,
val connection: DBConnection,
val environment: Environment,
val messagesApi: MessagesApi,
val configuration: Configuration)
extends Controller with Secured with I18nSupport {
def index = IsAuthenticatedAsync { username =>
implicit request =>
userService.getByEmailAddress(username).flatMap(currentUser =>
getIndex(currentUser))
}
private def getIndex(normalUser: Option[User])(implicit flash: Flash) =
normalUser match {
case Some(user) => getMenuPerDayPerPerson(user)
case None => Future.successful(Unauthorized)
}
private def getMenuPerDayPerPerson(user: User)(implicit flash: Flash) = {
val userIsAdmin = userService.isAdminUser(user.emailAddress)
menuPerDayPerPersonService.getAllMenuWithNamePerDayWithDishesPerPerson(user.uuid).map(_.toArray)
.map(menusPerDayPerPerson =>
Ok(views.html.menuPerDayPerPerson(
user.copy(isAdmin = userIsAdmin),
menusPerDayPerPerson,
MenuPerDayPerPersonForm.menuPerDayPerPersonForm)))
}
}
示例3: CustomerProfileServiceImpl
//设置package包名称以及导入依赖的类
package services.profile.impl
import java.util.UUID
import com.google.inject.Inject
import daos.customer.CustomerProfileDAO
import models.CustomerInfo
import services.profile.CustomerProfileService
import play.api.libs.concurrent.Execution.Implicits._
import scala.concurrent.Future
class CustomerProfileServiceImpl @Inject() (profileDAO: CustomerProfileDAO) extends CustomerProfileService {
def edit(userID: UUID, profile: CustomerInfo): Future[CustomerInfo] = {
profileDAO.find(userID).flatMap {
case Some(customerInfo) =>
profileDAO.save(userID, profile)
case None => profileDAO.save(userID, profile)
}
}
def view(userID: UUID): Future[Option[CustomerInfo]] = profileDAO.find(userID)
}
示例4: MerchantCertificatesServiceImpl
//设置package包名称以及导入依赖的类
package services.merchant.impl
import java.util.UUID
import com.google.inject.Inject
import daos.merchant.{ MerchantAreasDAO, MerchantCertificatesDAO }
import daos.util.CertificateDAO
import models._
import services.merchant.{ MerchantAreasService, MerchantCertificatesService }
import scala.concurrent.ExecutionContext.Implicits._
import scala.concurrent.Future
class MerchantCertificatesServiceImpl @Inject() (merchantCertificatesDAO: MerchantCertificatesDAO, certDAO: CertificateDAO) extends MerchantCertificatesService {
def add(userID: UUID, cert: MerchantCertificate): Future[MerchantCertificate] = merchantCertificatesDAO.save(userID, cert)
def edit(cert: MerchantCertificate): Future[MerchantCertificate] = certDAO.save(cert)
def view(userID: UUID): Future[MerchantCertificates] = merchantCertificatesDAO.find(userID)
def clear(userID: UUID): Future[MerchantCertificates] = merchantCertificatesDAO.clear(userID)
def deleteOne(userID: UUID, cert: MerchantCertificate): Future[MerchantCertificate] = {
certDAO.delete(cert)
merchantCertificatesDAO.deleteOne(userID, cert)
}
}
示例5: StoryServiceFactory
//设置package包名称以及导入依赖的类
package io.soheila.cms.services.stories
import com.google.inject.Inject
import com.google.inject.name.Named
import io.soheila.cms.daos.StoryDAO
import io.soheila.cms.services.stories.fsm.{ Edited, Published, StoryState }
class StoryServiceFactory @Inject() (@Named("storyDAO") val storyDAO: StoryDAO, @Named("publishedStoryDAO") val publishedStory: StoryDAO) {
private val StoryServiceMap: Map[String, StoryService] = Map(
Published.getClass.getSimpleName -> new StoryServiceImpl(publishedStory)
).withDefaultValue(new StoryServiceImpl(storyDAO))
def getStoryService(storyState: StoryState): StoryService = {
StoryServiceMap(storyState.getClass.getSimpleName)
}
def getStoryService(published: Boolean): StoryService = {
if (published) getStoryService(Published)
else getStoryService(Edited)
}
def getDefaultStoryService: StoryService = {
getStoryService(Edited)
}
def getPublishedStoryService: StoryService = {
getStoryService(Published)
}
}
示例6: CloudinaryStorageServiceImpl
//设置package包名称以及导入依赖的类
package io.soheila.cms.services.media.cloudinary
import cloudinary.model.CloudinaryResourceBuilder
import com.cloudinary.Cloudinary
import com.google.inject.Inject
import io.soheila.cms.services.media.ImageStorageService
import net.ceedubs.ficus.Ficus._
import play.api.Configuration
class CloudinaryStorageServiceImpl @Inject() (val cloudinaryResourceBuilder: CloudinaryResourceBuilder, configuration: Configuration) extends ImageStorageService {
implicit val cloudinaryClient: Cloudinary = cloudinaryResourceBuilder.cld
private val config = configuration.underlying
override def generateSignature(paramsToSign: Map[String, _]): String = {
val secret = config.as[String]("cloudinary.api_secret")
val params = paramsToSign.toList.sortBy(_._1) collect {
case (k, v: Iterable[_]) => s"$k=${v.mkString(",")}"
case (k, v) if v != null && v.toString != "" =>
val value = v.toString.replace("\"", "")
s"$k=$value"
}
Cloudinary.sign(params.mkString("&"), secret).map("%02X" format _).mkString
}
}
示例7: ClientRecord
//设置package包名称以及导入依赖的类
package services.database
import com.google.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.libs.json.Json
import slick.driver.JdbcProfile
case class ClientRecord(id: Int, firstName: String, lastName: String, petId: Int)
object ClientRecord {
implicit val clientRecordFormat = Json.format[ClientRecord]
}
class ClientsRepo @Inject()(protected val dbConfigProvider: DatabaseConfigProvider) {
val dbConfig = dbConfigProvider.get[JdbcProfile]
val db = dbConfig.db
import dbConfig.driver.api._
val clients = TableQuery[ClientsTable]
class ClientsTable(tag: Tag) extends Table[ClientRecord](tag, "CLIENTS") {
def id = column[Int]("ID", O.AutoInc, O.PrimaryKey)
def firstName = column[String]("FIRST_NAME")
def lastName = column[String]("LAST_NAME")
def petId = column[Int]("PET_ID")
def * = (id, firstName, lastName, petId) <> ((ClientRecord.apply _).tupled, ClientRecord.unapply)
}
}
示例8: User
//设置package包名称以及导入依赖的类
package com.bob.reservefund.scala.Controller
import com.bob.reservefund.scala.Service.UserService
import com.bob.reservefund.scala.Util.EnvironmentContext
import com.google.inject.{Inject, Singleton}
import com.twitter.finagle.http.Request
import com.twitter.finatra.annotations.Flag
import com.twitter.finatra.http.request.RequestUtils
import com.bob.reservefund.scala.Filter.WhichUserLoginContext._
case class User(name: String, id: Int, age: Int)
@Singleton
class UserController @Inject()(userService: UserService, @Flag("active.environment") env: String) extends FinatraController {
get("/users", swagger(o => {
o.summary("get all users")
.description("return all users item")
.tag("user")
.produces("application/json")
.responseWith[List[User]](200, "the response json", example = Some(List(User("bb", 1, 2))))
.responseWith[Unit](404, "the address is not found")
})) { request: Request =>
println(request.user.id)
info("users")
List(User(env, -1, -1), User(RequestUtils.pathUrl(request), 1, 1), Hello(userService.dbusername, 2, 2), Hello(EnvironmentContext.get("mqconfig.maxTryTimes", "fuck"), 3, 1))
}
get("/properties", swagger(o => {
o.summary("get all properties")
.description("return all properties item")
.tag("user")
.produces("application/json")
.responseWith[List[User]](200, "the response json", example = Some(List(User("bb", 1, 2))))
.responseWith[Unit](404, "the address is not found")
})) { request: Request =>
EnvironmentContext.toMap
}
}
示例9: show
//设置package包名称以及导入依赖的类
package controllers
import com.google.inject.Inject
import models._
import play.api.mvc.{Controller, Action}
import play.api.Play.current
import play.api.i18n.Messages.Implicits._
import scala.concurrent.duration._
import scala.concurrent.Await
class [email protected]()(userRepo: UserRepo) extends Controller {
def show = Action {
val userList = Await.result(userRepo.getAll,2 second)
// val awardList = Await.result(awardsRepo.getAll,2 second)
// val assignmentList = Await.result(assignmentRepo.getAll,2 second)
// val languageList = Await.result(languageRepo.getAll,2 second)
// val programminList = Await.result(programmingRepo.getAll,2 second)
Ok(views.html.intern(userList))
}
}
示例10: AdminController
//设置package包名称以及导入依赖的类
package controllers
import com.google.inject.Inject
import play.api.mvc.{Action, Controller}
import services.{AssignmentServiceApi, AdminServiceApi}
import scala.concurrent.ExecutionContext.Implicits.global
import play.api.i18n.Messages.Implicits._
import play.api.Play.current
class AdminController @Inject()(admin:AdminServiceApi,service:AssignmentServiceApi) extends Controller{
val list=admin.getAllRecords
def listAll=Action.async { implicit request =>
val id=request.session.get("id").get.toInt
service.getAssignmentById(id).map{ list =>
Ok(views.html.assignmentdis(list.toList))
}
}
def details=Action.async { implicit request =>
val id = request.session.get("id").get.toInt
admin.getAllRecords.map(res=> Ok(views.html.admindetails(res.toList)))
}
}
示例11: LanguageTable
//设置package包名称以及导入依赖的类
package repository
import com.google.inject.Inject
import com.google.inject.ImplementedBy
import models.Language
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfigProvider
import slick.driver.JdbcProfile
import scala.concurrent.Future
trait LanguageTable extends UserTable{ self: HasDatabaseConfigProvider[JdbcProfile] =>
import driver.api._
class LanguageTable(tag:Tag) extends Table[Language](tag,"language") {
val id=column[Int]("id")
val name= column[String]("name", O.SqlType("VARCHAR(200)"))
val fluency=column[String]("fluency", O.SqlType("VARCHAR(200)"))
def * = (id, name,fluency) <>(Language.tupled, Language.unapply)
}
val languageTableQuery = TableQuery[LanguageTable]
}
//@ImplementedBy(classOf[LanguageImpl])
class LanguageRepo @Inject() (protected val dbConfigProvider: DatabaseConfigProvider) extends LanguageTable with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
def insert(id: Int, name: String, fluency: String): Future[Int] = {
val insertQuery=languageTableQuery += Language(id, name, fluency)
db.run {insertQuery}
}
def update(id: Int, name: String, fluency: String): Future[Int] = db.run {languageTableQuery.filter(_.id === id).update(Language(id, name, fluency))}
def delete(name:String): Future[Int] = db.run { languageTableQuery.filter(_.name === name).delete}
def getAll(): Future[List[Language]] = db.run {
val test=languageTableQuery.to[List]
test.result
}
def getLanguage(id:Int): Future[Seq[Language]] = {
db.run(languageTableQuery.filter(_.id === id).result)
}
}
示例12: insertAssignment
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.Assignment
import repository.AssignmentRepo
import scala.concurrent.Future
@ImplementedBy(classOf[AssignmentService])
trait AssignmentServiceApi{
def insertAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]
def updateAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]
def deleteAssignment(id:Int):Future[Int]
def getAssignment:Future[List[Assignment]]
def getAssignmentById(id:Int):Future[Seq[Assignment]]
}
class AssignmentService @Inject()(assignment:AssignmentRepo) extends AssignmentServiceApi{
def insertAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]={
assignment.insert(id,name,marks,remarks)
}
def updateAssignment(id:Int,name:String,marks:Int,remarks:String):Future[Int]={
assignment.update(id,name,marks,remarks)
}
def deleteAssignment(id:Int):Future[Int]={
assignment.delete(id)
}
def getAssignment:Future[List[Assignment]]={
assignment.getAll()
}
def getAssignmentById(id:Int):Future[Seq[Assignment]]= {
assignment.getAssignment(id)
}
}
示例13: getAllRecords
//设置package包名称以及导入依赖的类
package services
import com.google.inject.{ImplementedBy, Inject}
import models.User
import slick.lifted.Query
import scala.concurrent.Future
@ImplementedBy(classOf[AdminService])
trait AdminServiceApi{
def getAllRecords:Future[List[User]]
//def getAllRecords():Future[Seq[(Int,String,String,String,String,String,String)]]
}
class AdminService @Inject()(admin:AdminRepo) extends AdminServiceApi{
// def getAllRecords():Future[Seq[(Int,String,String,String,String,String,String)]]={
// admin.getAll().map(res=>res)
// }
def getAllRecords:Future[List[User]]={
admin.getAll()
}
}
示例14: Session
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.Singleton
import com.google.inject.Inject
import play.api.mvc._
import play.api.libs.json._
import com.gilt.akk.cluster.api.test.v0.models.json._
import service.SessionService
import scala.concurrent.ExecutionContext.Implicits.global
@Singleton
class Session @Inject()(sessionService: SessionService) {
def get() = Action.async {
implicit request => {
sessionService.get().map(
session => Results.Ok(Json.toJson(session))
)
}
}
}
示例15: Login
//设置package包名称以及导入依赖的类
package controllers
import application.user.login.AuthenticationServices
import com.google.inject.Inject
import dal.repositories.authentication.{AuthenticationRepository}
import datastructures.LoginUser
import play.api.data.Forms._
import play.api.data._
import play.api.mvc.{Action, Controller}
class Login @Inject() (authentication: AuthenticationServices) extends Controller {
val loginUser : Form[LoginUser] = Form( mapping(
"username" -> nonEmptyText,
"password" -> nonEmptyText) (LoginUser.apply)(LoginUser.unapply) )
def getLogin = Action {
request =>
loginUser.bindFromRequest()(request).fold(
formWithErrors => BadRequest,
userData => {
val response = authentication.authenticated(userData.username, userData.password)
response match {
case Some(x) => Status(401)(authentication.makeToken(x))
case None => Ok(authentication.unauthenticatedResponse)
}
})
}
}