Skip to content

Instantly share code, notes, and snippets.

@OlegIlyenko
Created May 17, 2013 20:39
Show Gist options
  • Select an option

  • Save OlegIlyenko/5601831 to your computer and use it in GitHub Desktop.

Select an option

Save OlegIlyenko/5601831 to your computer and use it in GitHub Desktop.
Fixed version of SecureModule
import scaldi.{Injector, Module, Injectable}
trait Security {
type User
def authenticate(username: String, password: String): Boolean
}
class SecuritySample extends Security {
def authenticate(username: String, password: String): Boolean = false
}
class SecurityImpl extends Security {
def authenticate(username: String, password: String): Boolean = {
User.authenticate(username, password) match {
case Some(user: User) => true
case _ => false
}
}
}
class ModSec(implicit inj: Injector) extends Injectable {
def secure = inject [Security] (identified by 'secure and by default new SecuritySample)
}
object ConfigModule extends Module {
bind [Security] as 'secure to new SecurityImpl
bind [ModSec] to new ModSec
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment