com.google.inject.ImplementedBy Scala Examples
The following examples show how to use com.google.inject.ImplementedBy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: AuthJourney.scala From pertax-frontend with Apache License 2.0 | 5 votes |
package controllers.auth import com.google.inject.{ImplementedBy, Inject} import controllers.auth.requests.UserRequest import play.api.mvc.{ActionBuilder, AnyContent, ControllerComponents} @ImplementedBy(classOf[AuthJourneyImpl]) trait AuthJourney { val authWithPersonalDetails: ActionBuilder[UserRequest, AnyContent] val authWithSelfAssessment: ActionBuilder[UserRequest, AnyContent] val minimumAuthWithSelfAssessment: ActionBuilder[UserRequest, AnyContent] } class AuthJourneyImpl @Inject()( authAction: AuthAction, minimumAuthAction: MinimumAuthAction, selfAssessmentStatusAction: SelfAssessmentStatusAction, getPersonDetailsAction: GetPersonDetailsAction, cc: ControllerComponents) extends AuthJourney { override val authWithPersonalDetails : ActionBuilder[UserRequest, AnyContent] = authAction andThen selfAssessmentStatusAction andThen getPersonDetailsAction override val authWithSelfAssessment : ActionBuilder[UserRequest, AnyContent] = authAction andThen selfAssessmentStatusAction override val minimumAuthWithSelfAssessment : ActionBuilder[UserRequest, AnyContent] = minimumAuthAction andThen selfAssessmentStatusAction }
Example 2
Source File: PdfGeneratorConnector.scala From pertax-frontend with Apache License 2.0 | 5 votes |
package connectors import com.google.inject.{ImplementedBy, Inject, Singleton} import play.api.Mode import play.api.libs.ws.{WSClient, WSResponse} import play.api.{Configuration, Environment} import uk.gov.hmrc.play.bootstrap.config.ServicesConfig import scala.concurrent.Future @ImplementedBy(classOf[FrontendPdfGeneratorConnector]) trait PdfGeneratorConnector { val serviceURL: String def getWsClient: WSClient def generatePdf(html: String): Future[WSResponse] = getWsClient.url(serviceURL).post(Map("html" -> Seq(html))) } @Singleton class FrontendPdfGeneratorConnector @Inject()( environment: Environment, runModeConfiguration: Configuration, wsClient: WSClient, servicesConfig: ServicesConfig) extends PdfGeneratorConnector { val mode: Mode = environment.mode val pdfServiceUrl: String = servicesConfig.baseUrl("pdf-generator-service") val serviceURL = pdfServiceUrl + "/pdf-generator-service/generate" override def getWsClient: WSClient = wsClient }
Example 3
Source File: MailService.scala From crm-seed with Apache License 2.0 | 5 votes |
package com.dataengi.crm.common.services.mailer import com.google.inject.{ImplementedBy, Inject} import com.dataengi.crm.common.configurations.mailer.MailerConfiguration import com.dataengi.crm.common.context.types._ import play.api.libs.mailer.{Email, MailerClient} import cats.instances.all._ import scala.concurrent.ExecutionContext case class MailData(subject: String, bodyHtml: Option[String], bodyText: Option[String]) @ImplementedBy(classOf[MailServiceImplementation]) //TODO move to module conf trait MailService { def sendEmail(recipients: String*)(mailData: MailData): Or[String] } class MailServiceImplementation @Inject()(mailerClient: MailerClient, configuration: MailerConfiguration, implicit val executionContext: ExecutionContext) extends MailService { override def sendEmail(recipients: String*)(mailData: MailData): Or[String] = { for { from <- configuration.from() } yield { mailerClient.send(Email(mailData.subject, from, recipients, mailData.bodyText, mailData.bodyHtml)) } } }
Example 4
Source File: ClientsModule.scala From daf-semantics with Apache License 2.0 | 5 votes |
package modules import com.google.inject.ImplementedBy import play.api.inject.ApplicationLifecycle import javax.inject.Singleton import javax.inject.Inject import play.api.libs.ws.WSClient import play.api.Application import play.api.Environment import play.api.Configuration import scala.concurrent.ExecutionContext import scala.concurrent.Future import play.Logger import clients.OntonetHubClient import com.typesafe.config.ConfigFactory import com.typesafe.config.ConfigRenderOptions @ImplementedBy(classOf[ClientsModuleBase]) trait ClientsModule @Singleton class ClientsModuleBase @Inject() (lifecycle: ApplicationLifecycle, ws: WSClient, configuration: Configuration) extends ClientsModule { val conf_clients = configuration.underlying .getConfig("clients") val ontonethub_config = conf_clients.getConfig("ontonethub") // TODO: verify if default configurations are needed here val ontonethub = new OntonetHubClient(ws, ontonethub_config) // TESTING ................................................ val options = ConfigRenderOptions.concise() .setComments(false).setOriginComments(false) .setFormatted(true).setJson(true) val json = ontonethub_config.root().render(options) // TESTING ................................................ // when application starts... @Inject def onStart( app: Application, env: Environment)(implicit ec: ExecutionContext) { Logger.info("ClientsModuleBase START") println("\n\n\n\n\n\n") println(json) } // when application stops... lifecycle.addStopHook({ () => Future.successful { Logger.info("ClientsModuleBase STOP") } }) }
Example 5
Source File: KBModule.scala From daf-semantics with Apache License 2.0 | 5 votes |
package modules import javax.inject._ import play.api.inject.ApplicationLifecycle import play.api.mvc._ import scala.concurrent.Future import com.google.inject.ImplementedBy import play.api.Play import play.api.Application import play.api.Environment import play.api.Configuration import scala.concurrent.ExecutionContext import play.api.Logger import it.almawave.linkeddata.kb.utils.ConfigHelper import it.almawave.linkeddata.kb.repo._ import scala.concurrent.ExecutionContext.Implicits.global import java.nio.file.Paths import play.api.Mode import java.io.File import it.almawave.linkeddata.kb.repo.RDFRepository import com.typesafe.config.ConfigFactory @ImplementedBy(classOf[KBModuleBase]) trait KBModule @Singleton class KBModuleBase @Inject() (lifecycle: ApplicationLifecycle) extends KBModule { // TODO: SPI per dev / prod val kbrepo = RDFRepository.memory() val logger = Logger.underlyingLogger // when application starts... @Inject def onStart( env: Environment, configuration: Configuration)(implicit ec: ExecutionContext) { // get configs val app_type = configuration.underlying.getString("app.type") val data_dir = app_type match { case "dev" => "./dist/data" case "prod" => "./data" } logger.debug(s"app_type: ${app_type}") logger.debug(s"data_dir: ${data_dir}") // starting VocabularyAPI service var conf_voc = ConfigFactory.parseFile(new File("./conf/semantic_repository.conf").getAbsoluteFile) conf_voc = ConfigHelper.injectParameters(conf_voc, ("data_dir", data_dir)) kbrepo.configuration(conf_voc) logger.info("KBModule.START....") logger.debug("KBModule using configuration:\n" + ConfigHelper.pretty(conf_voc)) println("KBModule using configuration:\n" + ConfigHelper.pretty(conf_voc)) // this is needed for ensure proper connection(s) etc kbrepo.start() // CHECK the initial (total) triples count var triples = kbrepo.store.size() logger.info(s"KBModule> ${triples} triples loaded") } // when application stops... lifecycle.addStopHook({ () => Future.successful { // this is useful for saving files, closing connections, release indexes, etc kbrepo.stop() logger.info("KBModule.STOP....") } }) }
Example 6
Source File: ExcludedAuthActionImpl.scala From nisp-frontend with Apache License 2.0 | 5 votes |
package uk.gov.hmrc.nisp.controllers.auth import java.net.{URI, URLEncoder} import com.google.inject.{ImplementedBy, Inject} import play.api.mvc.Results.Redirect import play.api.mvc.{ActionBuilder, ActionFunction, Request, Result} import uk.gov.hmrc.auth.core._ import uk.gov.hmrc.auth.core.retrieve.v2.Retrievals import uk.gov.hmrc.auth.core.retrieve.~ import uk.gov.hmrc.domain.Nino import uk.gov.hmrc.http.HeaderCarrier import uk.gov.hmrc.nisp.config.ApplicationConfig import uk.gov.hmrc.play.HeaderCarrierConverter import scala.concurrent.{ExecutionContext, Future} class ExcludedAuthActionImpl @Inject()(override val authConnector: PlayAuthConnector) (implicit ec: ExecutionContext) extends ExcludedAuthAction with AuthorisedFunctions { override def invokeBlock[A](request: Request[A], block: ExcludedAuthenticatedRequest[A] => Future[Result]): Future[Result] = { implicit val hc: HeaderCarrier = HeaderCarrierConverter.fromHeadersAndSession(request.headers, Some(request.session)) authorised(ConfidenceLevel.L200) .retrieve(Retrievals.nino and Retrievals.confidenceLevel and Retrievals.credentials and Retrievals.loginTimes) { case Some(nino) ~ confidenceLevel ~ credentials ~ loginTimes => block(ExcludedAuthenticatedRequest(request, Nino(nino), AuthDetails(confidenceLevel, credentials.map(creds => creds.providerType), loginTimes)) ) case _ => throw new RuntimeException("Can't find credentials for user") } recover { case _: NoActiveSession => Redirect(ApplicationConfig.ggSignInUrl, Map("continue" -> Seq(ApplicationConfig.postSignInRedirectUrl), "origin" -> Seq("nisp-frontend"), "accountType" -> Seq("individual"))) case _: InsufficientConfidenceLevel => Redirect(ivUpliftURI.toURL.toString) } } private val ivUpliftURI: URI = new URI(s"${ApplicationConfig.ivUpliftUrl}?origin=NISP&" + s"completionURL=${URLEncoder.encode(ApplicationConfig.postSignInRedirectUrl, "UTF-8")}&" + s"failureURL=${URLEncoder.encode(ApplicationConfig.notAuthorisedRedirectUrl, "UTF-8")}" + s"&confidenceLevel=200") } @ImplementedBy(classOf[ExcludedAuthActionImpl]) trait ExcludedAuthAction extends ActionBuilder[ExcludedAuthenticatedRequest] with ActionFunction[Request, ExcludedAuthenticatedRequest]
Example 7
Source File: VersionRoutingMap.scala From vat-api with Apache License 2.0 | 5 votes |
package routing import com.google.inject.ImplementedBy import config.{AppConfig, FeatureSwitch} import definition.Versions.VERSION_1 import javax.inject.Inject import play.api.Logger import play.api.routing.Router // So that we can have API-independent implementations of // VersionRoutingRequestHandler and VersionRoutingRequestHandlerSpec // implement this for the specific API... @ImplementedBy(classOf[VersionRoutingMapImpl]) trait VersionRoutingMap { val defaultRouter: Router val map: Map[String, Router] final def versionRouter(version: String): Option[Router] = map.get(version) } // Add routes corresponding to available versions... case class VersionRoutingMapImpl @Inject()(appConfig: AppConfig, defaultRouter: Router, liveRouter: live.Routes, v1Router: v1.Routes, v1RouterProd: v1Prod.Routes) extends VersionRoutingMap { val featureSwitch = FeatureSwitch(appConfig.featureSwitch) val map: Map[String, Router] = Map( VERSION_1 -> { if (featureSwitch.refactorEnabled) { if (featureSwitch.refactorProdEnabled) { Logger.info("[VersionRoutingMap][map] using v1Router - pointing to new packages for Obligations") v1RouterProd } else { Logger.info("[VersionRoutingMap][map] using v1Router - pointing to new packages") v1Router } } else { Logger.info("[VersionRoutingMap][map] using legacy liveRouter") liveRouter } } ) }
Example 8
Source File: LaboratoryControllerSuccessfulSpec.scala From Aton with GNU General Public License v3.0 | 5 votes |
package controllers.admin import scala.concurrent.ExecutionContext import scala.concurrent.Future import org.mockito.Matchers.any import org.mockito.Mockito.when import com.google.inject.ImplementedBy import com.google.inject.Inject import jp.t2v.lab.play2.auth.test.Helpers.AuthFakeRequest import model.Laboratory import model.Role import model.User import model.form.LaboratoryForm import model.form.data.LaboratoryFormData import model.json.{LaboratoryJson, LoginJson} import play.api.Environment import play.api.i18n.MessagesApi import play.api.libs.json.Json import play.api.test.FakeRequest import play.test.WithApplication import services.LaboratoryService import services.RoomService import services.UserService import services.impl.LaboratoryServiceImpl import services.state import services.state.ActionState import test.ControllerTest class LaboratoryControllerSuccessfulSpec extends LaboratoryControllerSpec { val labService: LaboratoryService = mockLaboratoryService(state.ActionCompleted) // Controller to be tested, with the dependencies lazy val controller = new LaboratoryController(labService, messagesApi)(userService, executionContext, environment) "Laboratory Controller on successful operations" should { "return Ok <200> status on receiving an edited laboratory" in { import laboratory._ val laboratoryData = LaboratoryFormData(name, location, administration) val laboratoryForm = LaboratoryForm.form.fill(laboratoryData) val result = controller.update.apply { FakeRequest() .withLoggedIn(controller)(loggedInUser) .withJsonBody(Json.toJson(laboratory)) } assertFutureResultStatus(result, 200) } "return Ok <200> status on deleting a laboratory" in { val result = controller.delete(laboratory.id).apply { FakeRequest() .withLoggedIn(controller)(LoginJson("admin", "adminaton")) } assertFutureResultStatus(result, 200) } "return Ok <200> status on adding a new laboratory" in { import laboratory._ val laboratoryData = LaboratoryJson(name, location, administration) val result = controller.add.apply { FakeRequest() .withLoggedIn(controller)(loggedInUser) .withJsonBody(Json.toJson(laboratoryData)) } assertFutureResultStatus(result, 200) } "return Ok <200> status when listing all laboratories" in pending "return laboratory list json when listing all laboratories" in pending } }
Example 9
Source File: LoggingProvider.scala From HAT2.0 with GNU Affero General Public License v3.0 | 5 votes |
package org.hatdex.hat.utils import com.google.inject.ImplementedBy import play.api.Logger @ImplementedBy(classOf[DefaultLoggingProvider]) trait LoggingProvider { def logger(clazz: Class[_]): Logger } class DefaultLoggingProvider extends LoggingProvider { def logger(clazz: Class[_]): Logger = { Logger(clazz) } } class MockLoggingProvider(mockLogger: Logger) extends LoggingProvider { def logger(clazz: Class[_]): Logger = { mockLogger } }
Example 10
Source File: DBService.scala From template-site with MIT License | 5 votes |
package services.db import javax.inject.{Inject, Singleton} import com.google.inject.ImplementedBy import play.api.db.slick.DatabaseConfigProvider import slick.dbio.{DBIOAction, NoStream} import slick.driver.JdbcProfile import scala.concurrent.duration.Duration import scala.concurrent.{Await, Future} @ImplementedBy(classOf[DBServiceImpl]) trait DBService { def runAsync[R](a: DBIOAction[R, NoStream, Nothing]): Future[R] def run[R](a: DBIOAction[R, NoStream, Nothing]): R } @Singleton class DBServiceImpl @Inject()(val dbConfigProvider: DatabaseConfigProvider) extends DBService { private val db = dbConfigProvider.get[JdbcProfile].db def runAsync[R](a: DBIOAction[R, NoStream, Nothing]): Future[R] = { db.run(a) } def run[R](a: DBIOAction[R, NoStream, Nothing]): R = { Await.result(runAsync(a), Duration.Inf) } }
Example 11
Source File: SundialDaoFactory.scala From sundial with MIT License | 5 votes |
package dao import com.google.inject.ImplementedBy import dao.postgres.PostgresSundialDaoFactory @ImplementedBy(classOf[PostgresSundialDaoFactory]) trait SundialDaoFactory { def buildSundialDao(): SundialDao def withSundialDao[T](f: SundialDao => T) = { val dao = buildSundialDao() try { f(dao) } finally { dao.close() } } }