4

I'm not asking for opinion here but facts

I'm trying to pick a new DI. I have had some experience with Guice. Overall i would said that one advantage of it, is that when from scala you need to integrate with Java, Guice does the job. So for interoperability it's a clear plus.

If we put aside this interoperability issue, can anyone, give me a brief comparison between

scaladi, guice, Macwire?

I'm still new at understanding scaldi. One thing that i found surprising is the idea of having to move around around your injector trough an implicit parameter. I never almost did that in guice. I either wire up everything in my main, or use assisted injection, hence passing around the factories to the class that needs some specific instance.

If someone could further elaborate on that design choice i would appreciate.

Many thanks,

-M-

Here is something strange i found with macWire:

trait Interf {
  def name:String
}

class InterfImpl(val name:String) extends Interf

trait AModule {

  import com.softwaremill.macwire.MacwireMacros._


   //lazy val aName: String = "aName"
   lazy val theInterf: Interf = wire[InterfImpl]

}

object injector extends AModule

println(injector.theInterf.name)

I get a strange value. I don't know what macWire is doing at that level. I though it could make a compile error or something. Indeed, i did not give any String value.

1

1 Answer 1

4
  • Guice: Typical DI during runtime (reflection based)
  • Macwire: Uses Scala Macros to generate to the wiring before it gets compiled (Compile time safe DI!)
  • scaladi: Never used this one

To have a solid and compile time safe DI in Scala you can also use the Cake Pattern (just google for "scala cake pattern")

Sign up to request clarification or add additional context in comments.

3 Comments

Thx. what is your conclusion of MacWire, are you sticking to it, or you went back to guice. I found some strange behavior with it. I re-edit the question for convenience.
I don't want to be to Scala specific for compatibility purpose.
Macros are still tagged as "Experimental" see: docs.scala-lang.org/overviews/macros/overview.html , because of this i never used it in production, just played around with it a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.