我在播放框架中使用 Silhouette 库时遇到问题,我正在使用 guice 进行运行时依赖注入,在创建接受 DelegableAuthInfoDAO 作为参数的 DelegableAuthInfoRepository 时出现错误,它说 DelegableAuthInfoDAO 未绑定到具体实例,即使我已经完成了在配置方法中绑定,这是我在启用模块时遇到的错误
play.api.UnexpectedException: Unexpected exception[CreationException: Unable
to create injector, see the following errors:
1) No implementation for
com.mohiva.play.silhouette.persistence.
daos.DelegableAuthInfoDAO<com.mohiva.pla
y.silhouette.api.util.PasswordInfo> was bound.
while locating
com.mohiva.play.silhouette.persistence.daos
.DelegableAuthInfoDAO<com.mohiva.play
.silhouette.api.util.PasswordInfo>
for the 1st parameter of
modules.authModule.provideAuthInfoRepository(authModule.scala:112)
at modules.authModule.provideAuthInfoRepository(authModule.scala:112) (via
modules: com.google.inject.util.Modules$OverrideModule ->
modules.authModule)
以下是模块中完成的一些配置:
@Provides
def provideAuthInfoRepository(passwordInfoDAO: DelegableAuthInfoDAO[PasswordInfo]): AuthInfoRepository = {
new DelegableAuthInfoRepository(passwordInfoDAO)
}
override def configure() = {
bind(classOf[UserDAO]).asEagerSingleton()
bind(classOf[IdentityService[User]]).to(classOf[UserService])
bind(classOf[CacheLayer]).to(classOf[PlayCacheLayer])
bind(classOf[PasswordHasher]).toInstance(new BCryptPasswordHasher())
bind(classOf[EventBus]).toInstance(new EventBus)
bind(classOf[DelegableAuthInfoDAO[PasswordInfo]]).toInstance(new InMemoryAuthInfoDAO[PasswordInfo]())
bind(classOf[IDGenerator]).toInstance(new SecureRandomIDGenerator())
bind(classOf[FingerprintGenerator]).toInstance(new DefaultFingerprintGenerator(false))
bind(classOf[Clock]).toInstance(Clock())
}