Questions tagged [macwire]

Lightweight and Nonintrusive Scala Dependency Injection Library

MacWire is a lightweight and Nonintrusive Scala Dependency Injection Library.

MacWire generates new instance creation code of given classes, using values in the enclosing type for constructor parameters, with the help of Scala Macros.

For a general introduction to DI in Scala, take a look at the Guide to DI in Scala, which also features MacWire.

MacWire helps to implement the Dependency Injection (DI) pattern, by removing the need to write the class-wiring code by hand. Instead, it is enough to declare which classes should be wired, and how the instances should be accessed (see Scopes).

Classes that should be wired should be organized in "modules", which can be Scala traits, classes or objects. Multiple modules can be combined using inheritance; values from the inherited modules are also used for wiring.

MacWire can be in many cases a replacement for DI containers, offering greater control on when and how classes are instantiated, typesafety and using only language (Scala) mechanisms.

Documentation

26 questions
7
votes
2 answers

How to set up play framework ApplicationLoader and Macwire to work with custom routes?

I set up the application loader this way: class MyProjectApplicationLoader extends ApplicationLoader { def load(context: Context): Application = new ApplicationComponents(context).application } class ApplicationComponents(context: Context)…
3
votes
1 answer

Inject database connection pool

I have started using MacWire for the dependency injection of my Play app, and I am having problems trying to inject the database connection. Before using DI, my code looked like this: DB.withConnection { implicit connection => ... } This is not…
Miguel
  • 1,201
  • 2
  • 13
  • 30
2
votes
0 answers

MacWire: Is it possible to get automatic wiring of recursively dependent case classes, as in @Inject with Guice?

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…
Gal
  • 5,338
  • 5
  • 33
  • 55
2
votes
0 answers

Can't import Play Routes for subprojects using DI with Macwire

I'm working on a Play 2.6 project using compiled DI and sub-projects: One difference from a regular Play project is that I create a package under app, so controllers are located at com.company.my.controllers.InfoController. Here is the…
raul782
  • 479
  • 1
  • 5
  • 15
2
votes
0 answers

Macwire how to wire actorref self instance

I'm exploring Macwire DI framework for Scala and while doing it I faced a problem. I have a dispatcher actor that creates a bunch of actors that are dependent on the dispatcher. Dispatcher controls all the message flow between its child…
2
votes
1 answer

Fail to wire play dependancies with Macwire

i have a api service class that is dependent on play's Configuration and WSClient instancees. and I dont want to use @Inject() anotation cause I want to use compile-time injection with Macwire so what i did is this: // this is a trait that here im…
jack miao
  • 1,398
  • 1
  • 16
  • 32
2
votes
2 answers

how to inject dependencies to a service with MacWire (play framework)

I have a service class, and the service have one method getSomethingFromApi , now , I want to have play Configuration instance so I can pull stuff from the application.conf, and a play WSClient so I can perform http calls. this is how I want my…
jack miao
  • 1,398
  • 1
  • 16
  • 32
2
votes
3 answers

DI or Service Locator : Injecting implementations at run-time ( no static binding ) in scala

i have a use case where i would like to offer a simple API to extend the functionality of my scala application. i've spent the last couple of days trying to find a java/scala DI framework or library that does the following for me: identifies…
pgn
  • 669
  • 1
  • 6
  • 16
2
votes
2 answers

How to run httpFilters in playframework 2.4

I am trying to build application on Playframework 2.4 with macwire DI, and I have problem with httpFilters from Play ! Here is an example what I'm trying to do class ExampleFilter extends Filter { def apply(nextFilter: RequestHeader =>…
mrxelik
  • 41
  • 2
1
vote
0 answers

Does the Scala.js ecosystem offer any way(s) to augment or replace the auto-generated setter/mutator methods for property fields of scala classes?

Please consider a family of plain and case classes, cross-compiled to JVM and Scala.js, which make mixed use of properties with automatically and manually defined accessor methods. Many come from external libraries but all inherit from a specific…
Ben McKenneby
  • 481
  • 4
  • 15
1
vote
1 answer

Macwire dependencies not being fulfilled

I am using wire in my scala project. I have a usecase --- class SchemaRegistry(registry: SchemaRegistryClient) class SchemaRegistryClient(url: String) extends RestService(url) {} trait EndpointModule { // Schema Registry endpoint dependency …
Shitij Goyal
  • 191
  • 1
  • 8
1
vote
1 answer

Does Play subprojects need each an ApplicationLoader with Macwire?

Given the following set of sub-projects: Play subproject can't import Play-json classes Should each Project need to have an independent ApplicationLoader? For example for the api module, should I create and ApiApplicationLoader and for the parent…
raul782
  • 479
  • 1
  • 5
  • 15
1
vote
0 answers

Is it possible to see the code generated by Macwire

Is it possible to see what is the code generated by wire macro lazy val securedRequestHandler : SecuredRequestHandler = wire[DefaultSecuredRequestHandler] In the above example, I want to know what arguments were passed when…
Manu Chadha
  • 15,555
  • 19
  • 91
  • 184
1
vote
1 answer

How to implement Actor based HTTP Routing in Akka

I'm new to Akka. While learning I've created a sample project on Github. Here this project uses Akka, Akka-HTTP, Slick, Flyway and Macwire. I wanted to implement Akka Actors for HTTP routing. I tried to implement this on redis/ but not working as…
Sujit Baniya
  • 895
  • 9
  • 27
1
vote
0 answers

How do I inject ReactiveMongoApi trait in a Repository with macwire?

I'm new to Play framework and all the Scala stack. I'm trying to implement dependency injection using macwire and ReactiveMongo to handle my MongoDB database. I have this classes to define repositories. trait BaseRepository extends…
1
2