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
1
vote
1 answer

MacWire: Found multiple values of type

I'm using MacWire DI framework and I'm geting this error. Found multiple values of type [play.api.mvc.DefaultActionBuilder]: [List(defaultActionBuilder, Action)] [error] override lazy val controllerComponents: DefaultControllerComponents =…
rodbs
  • 185
  • 1
  • 4
  • 12
1
vote
1 answer

Injecting playFramework dependancies to scala object using MacWire traits fail

Lets say I have bunch of car objects in my project, for example: object Porsche extends Car { override def start() {...} override def canStart(fuelInLitr: Int) = fuelInLitr > 5 override val fuelInLitr = 45 override val carId =…
1
vote
2 answers

Play 2.4 macwire example with extended controllers doesn't seem like it can be mocked

I took the existing macwire example and extended the controller like so CoffeeController.scala package com.softwaremill.play24.controllers import com.softwaremill.play24.dao.CoffeeDao import play.api.i18n.Lang import play.api.libs.json.Json import…
user2928738
  • 69
  • 1
  • 4
0
votes
1 answer

Error converting Play Silhouette Module from Guice To Macwire

I am trying to convert from Guice to Macwire as a dependency injection framework. It is going fine apart from this Silhouette Module where I am getting a compilation error. Error at bottom. Working Module in Guice: class SilhouetteModule…
Chris Johnston
  • 335
  • 1
  • 2
  • 16
0
votes
1 answer

Inject DatabaseConfigProvider with macwire

I have tried to add Slick to my project Create RoomRepo class class RoomRepo @Inject() (dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) extends HasDatabaseConfigProvider[JdbcProfile]{/**...*/} Inject it class ChatEngine…
Alexandr Lukovnikov
  • 170
  • 1
  • 5
  • 17
0
votes
1 answer

Setting up, Testing with compile-time Dependency Injection, with Playframework 2.6 Macwire

In my project I have this structure app/ --> common/ --> DefyProductsComponents --> DefyProductsLoader --> controllers/ --> HomeController DefyProductsComponents package common import com.softwaremill.macwire.wire import…
agusgambina
  • 6,229
  • 14
  • 54
  • 94
0
votes
1 answer

Akka actoreRef with macWire DI, actoreRef is not set

I have a 2 actors, Actor1 and Actor2. Actor1 wants to send MyMsg1 to Actor2, and Actor2 after doing some work and getting Future[MyMsg2] wants to send MyMsg2 to Actor1. I have got this working one way but it fails with DI. Scenario 1 - Working…
curiousengineer
  • 2,196
  • 5
  • 40
  • 59
0
votes
1 answer

Macwire, wireWith and implicit parameters

wireWith seems to have some issues with resolving implicit parameters. Minimal example: import com.softwaremill.macwire._ object A { def props(x: Int)(implicit y: String): A = new A(x) } class A(x: Int)(implicit y: String) { val sum: String…
J0HN
  • 26,063
  • 5
  • 54
  • 85
0
votes
1 answer

How to override macwire injectables in subclasses

The Play web framework allows injecting a list of "filters" to do common processing on requests (gzip, cors, logging, etc.) package play.api trait BuiltInComponents { ... lazy val httpFilters: Seq[EssentialFilter] = Nil
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
0
votes
1 answer

Error trying to inject a dependency in Lagom

I'm trying to create a simple service to send emails using Lagom framework and the Scaladsl. I'm trying to use the Play Mailer Plugin to handle emails but I'm struggling trying to inject it into the service implementation. I created the service…
Micho
  • 3,929
  • 13
  • 37
  • 40
0
votes
1 answer

How to inject a trait with macwire

I have a Scala trait trait UserRepository { def findByEmail(email: String): User } I would like to inject this into a service with MacWire class AccountService(){ val userRepo = wire[UserRepository] } And then use it in a test or class class…
decapo
  • 789
  • 3
  • 8
  • 25
1
2