I am using Play with Scala and I am trying to create a singleton, and i want to inject it from its trait and not directly.
for example:
@ImplementedBy(classOf[S3RepositoryImpl])
trait S3Repository {
}
@Singleton
class S3RepositoryImpl extends S3Repository {
}
But this fails with error:
trait Singleton is abstract; cannot be instantiated
I have tried several combinations and they all produce the same.
I come from Spring background and its very natural there? am i missing something about how Guice handles this type of Injection?
Thanks.
Use below import, instead of import javax.inject.Singleton
import com.google.inject.{Inject, Singleton}
As pointed out by @Tavian-Barnes, the solution is to ensure you have the following import:
import javax.inject.Singleton
Import both Inject and Singleton.
import javax.inject.{Inject, Singleton}
Refrain from using:
import com.google.inject.{Inject, Singleton}
as play framework requires the javax import
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With