Play2.6: Sv5 No implementation bound - provision exception for DI


#1

I’ve been banging my head over the since yesterday. As far as I can tell I have created the environment ok (have tried both the case class and the application.conf settings independently), but when I try to inject the environment with silhouette: Silhouette[JWTEnv], I get this error thrown.

I’ve seen the Bind suggestion in the docs, but don’t know what to do with that, I have ficus in the build.sbt

Any ideas? Thanks in advance.

Play 2.6, Scala 2.12.2, Silhouette 5.0.0-RC2

ProvisionException: Unable to provision, see the following errors:

1) No implementation for com.mohiva.play.silhouette.api.Silhouette<env.JWTEnv> was bound.
  while locating com.mohiva.play.silhouette.api.Silhouette<env.JWTEnv>
    for the 3rd parameter of controllers.AuthController.<init>(AuthController.scala:40)
  while locating controllers.AuthController
    for the 4th parameter of router.Routes.<init>(Routes.scala:38)
  while locating router.Routes
  while locating play.api.inject.RoutesProvider
  while locating play.api.routing.Router
    for the 1st parameter of play.api.http.JavaCompatibleHttpRequestHandler.<init>(HttpRequestHandler.scala:222)
  while locating play.api.http.JavaCompatibleHttpRequestHandler
  while locating play.api.http.HttpRequestHandler
    for the 6th parameter of play.api.DefaultApplication.<init>(Application.scala:236)
  at play.api.DefaultApplication.class(Application.scala:235)
  while locating play.api.DefaultApplication
  while locating play.api.Application

Here’s my sample controller exhibiting the issue

package controllers

import javax.inject.{Inject, Singleton}

import com.mohiva.play.silhouette.api._
import models.dto.UserDto
import env.JWTEnv
import play.api.libs.json.Json
import play.api.libs.mailer.{MailerClient}
import play.api.mvc.{AbstractController, Action, AnyContent, ControllerComponents, MessagesActionBuilder, MessagesRequest}

import scala.concurrent.ExecutionContext

@Singleton
class AuthController @Inject() (
  messagesAction: MessagesActionBuilder,
  cc: ControllerComponents,
  silhouette: Silhouette[JWTEnv],
  mailerClient: MailerClient)(implicit ec: ExecutionContext)
  extends AbstractController(cc) {

  def login: Action[AnyContent] = messagesAction { implicit request: MessagesRequest[AnyContent] =>
    UserDto.userForm.bindFromRequest.fold(
      formWithErrors => {
        Ok("Error with data")
      },
      user => {
        Ok(Json.toJson(user))
      }
    )
  }
}

#2

Turns out, despite having created the silhouette.module, I had not enabled it in the application.conf:

play.modules.enabled += "modules.SilhouetteModule"