Unable to inject SocialProviderRegistry


#1

I just started using Scala + Play and have downloaded the play-silhouette-slick-seed code, which is based on Silhouette 3.0. I’ve customized the code little bit and made it comply to Silhouette 4.0 (after looking at play-silhouette-angular-seed and play-silhouette-credentials-seed - both of which are based on Silhouette 4.0) . Everything compiles but then I get the following run time error:

Could not find a suitable constructor in com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry. 
Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry.class(SocialProvider.scala:124)
  while locating com.mohiva.play.silhouette.impl.providers.SocialProviderRegistry
    for the 3rd parameter of controllers.ApplicationController.<init>(ApplicationController.scala:14)

And here’s the code snippet that is referred in the error:

class ApplicationController @Inject()(
  val silhouette: Silhouette[CookieEnv],
  val messagesApi: MessagesApi,
  socialProviderRegistry: SocialProviderRegistry)
  extends AuthBaseController {

From my limited understanding, I think either I’m missing a binding (which I’ve no clue about) in my module or the SocialProviderRegistry constructor takes a sequence of SocialProvider, which is not provided at run time. Can anyone please comment if I’m on the right track and guide me on resolving this issue.


#2

You must have a binding like in the official seed template.

Generally, I recommend to use the official seed template as a staring point and then implement the DAO’s from the other seed templates. You could also start with the Silhouette Persistence ReactiveMongo implementation and adapt it for slick.


#3

Thanks for the note. Actually I did look at the official seed template as well in addition to the others that I’ve pointed out. But none of these templates have any code related to binding for the SocialProviderRegistry. That leads me to believe explicit binding for this class/type, if any, is not required. My guess is the issue might be else where and it just being manifested via the above error. I’ll take a look at the ReactiveMongo implementation as well and see if there is anything different.


#4

But none of these templates have any code related to binding for the SocialProviderRegistry.

Maybe you’ve looked at the wrong place. But the link I’ve posted, points directly to the binding.


#5

Yes I was indeed looking at the wrong place. I’m still new to the concept of DI and hence was looking for the bind[…] statements in the configure() method. Upon you pointing it out and reading guice wiki, I realized my mistake i.e. did not have the corresponding @provides methods. Thanks a lot and now it is working!