Is there a way to make this work (Scala 2.8.1):
class A class B def f(implicit b: B) {} implicit val a = new A implicit def aToB(a: A) = new B f(a)
Actually, my problem is related to injection of Lift (2.2) dependencies, I try to convert Vendor [T] to T and implicitly require it in the class constructor without adding import after each val:
object DependencyFactory extends Factory { implicit def vendorToVal[T](vendor: Vendor[T]): T = vendor.vend implicit val db = new FactoryMaker[DbAccess](Model) {} //uncommenting the following line makes it work, but can we avoid it? //import db._ implicit val userStore = new FactoryMaker[UserStore](new UserStore) {} }
Where is UserStore :
class UserStore(implicit db: DbAccess)
Am I doing something wrong?
UPDATE
Thanks to Easy Angel for answering the first part. But this does not solve the Lift DI problem, because it turns out that in the scope there is an opposite transformation (from T to Vendor [T]), and both of these lead to an error: implicit extension diverges.
Can this be solved?
UPDATE2
Another problem after the previous one: the presence of a transformation from some container [T] to T with an implicit instance of the container [U] in scope, and a function with an implicit parameter U also leads to a βvague implicit extensionβ:
class A case class Vendor[T](v: T) def f(implicit a: A) {} implicit val vendor = Vendor(new A) implicit def vendorToVal[T](implicit v: Vendor[T]) = vv f
Any clues?
source share