The following code fails at compile time:

object Foo {
  case class A()
  case class B(a: A)
  case class C(b: B)

  lazy val a = wire[A]
  // Error:(14, 22) Cannot find a value of type: [QuickMain.B]
  lazy val c = wire[C]
}

Is it possible to get macwire to automatically infer that it can create a B by creating an A (Honestly, lazy val a = wire[A] shouldn't even be necessary)? If macwire can't do it, is there another Scala framework that can do it in a typesafe manner (I know of Dagger, but I'm looking for a scala-based solution).

To illustrate, in Guice I could do the following:

public class JavaExample {
  public static class A {}

  public static class B {
    @Inject
    public B(A a) {}
  }

  public static class C {
    @Inject
    public C(B b) {}
  }

  public static void main(String[] args) {
    // No bindings necessary!
    var injector = Guice.createInjector();
    System.out.println(injector.getInstance(C.class));
  }
}
0

There are 0 answers