私は単純なサービスクラスを持っています
trait ItemService[+A] {
def getItem(id: Int): Option[A]
}
class MockItemService(implicit inj: Injector) extends ItemService[Item] with Injectable {
def getItem(id: Int) = {
Option(new Feature("My Headline",Author(2,"Barry White")))
}
}
scaldi im を使用して MockItemService を ItemService にバインドし、次のようにアクセスします
class Features(implicit inj: Injector) extends Controller with Injectable {
val itemService = inject [ItemService[Item]]
def item(cat:String, id:Int, urlTitle:String) = Action {
itemService.getItem(id).map { item => Ok(views.html.feature.item(item))
}.getOrElse(NotFound)
}
}
私が欲しいのは、アイテムがアイテムではなく機能タイプであることです。機能はアイテムを拡張します。