Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Christian Kaps
    @akkie

    I currently try to wire an actor with an implicit parameter. The project compiles but I get an IllegalArgumentException at runtime.

    The constructor looks as follow:

    class Connector(brokerService: BrokerService)(
      implicit
      ec: ExecutionContext
    ) extends Actor with LazyLogging

    The error is the follow:

    java.lang.IllegalArgumentException: no matching constructor found on class app.actors.Connector for arguments [class app.models.services.BrokerServiceImpl]

    If I remove the implicit parameter, all works as expected.

    Adam Warski
    @adamw
    @akkie can you post your Props?
    Christian Kaps
    @akkie
    @adamw I instantiate the actor with val connector: ActorRef = wireActor[Connector]("connector") The BrokerService is injected in the class which instantiates the connector actor.
    Adam Warski
    @adamw
    ah, this unwraps to Props(classOf[Connector], brokerService) which is the non-typesafe way of creating new instances of actors
    and is (or at least was) recommended some time ago as "the" way to do things
    if we would instead unwrap to Props(new Connector(brokerService)) things would work fine
    @akkie can you file a bug?
    I'll see if this is fixable easily :)
    or of course if you would like to try fixing yourself, that would be even better :)
    Christian Kaps
    @akkie
    Sorry for the late response. I've filled a bug.
    dvirf
    @dvirf

    Hello, when I use this code:

    import com.softwaremill.macwire._
      class SomeClass(name: String)
      lazy val someClass: SomeClass = {
        val name: String = "alice"
        wire[SomeClass]
      }

    I get a warning that

    local val name in lazy value someClass is never used

    I understand that the wire macro changes the code to new SomeClass(name), so in practice name is indeed used, however I am compiling with -Xfatal-warnings so it prevents me from compiling successfully.

    How can it be solved?

    Adam Warski
    @adamw
    @dvirf just tried and didn't get any warnings
    dvirf
    @dvirf
    @adamw can you try it with scala 2.12 and scalacOptions ++= Seq("-Xlint", "-Xfatal-warnings”) in your build.sbt?
    It will fail your compilation.
    I’m using compile time dependency injection to create the Router for my play app, and I get an unused error regarding my prefix (similar to line 31 here).
    Adam Warski
    @adamw
    @dvirf yes, it compiles under 2.12:
    > show scalacOptions
    [info] * -Xlint
    [info] * -Xfatal-warnings
    [success] Total time: 0 s, completed Feb 1, 2018 3:09:57 PM
    > ++2.12.3 test:compile
    [info] Setting version to 2.12.3
    [info] Reapplying settings...
    [info] Set current project to tests (in build file:/Users/adamw/projects/macwire/)
    [info] Compiling 3 Scala sources to /Users/adamw/projects/macwire/tests/target/scala-2.12/test-classes...
    [debug] Creating Constructor Tree for com.softwaremill.macwire.WorkpadApp.SomeClass
       [debug] Looking for targetConstructor arguments
          [debug] Looking for constructor for com.softwaremill.macwire.WorkpadApp.SomeClass
             [debug] There are 1 eligible constructors
                [debug] (name: String)com.softwaremill.macwire.WorkpadApp.SomeClass
             [debug] There are 0 constructors annotated with @javax.inject.Inject
             [debug] Found (name: String)com.softwaremill.macwire.WorkpadApp.SomeClass
          [debug] Building eligible values
             [debug] Type-checking found String for [name]
             [debug] Found name of type String in scope Local
             [debug] Inspecting parent App members
                [debug] Type-checking found App
                [debug] Found main of type (args: <?>)Unit in scope ParentOrModule
                [debug] Found delayedInit of type (body: => Unit)Unit in scope ParentOrModule
                [debug] Found executionStart of type => Long in scope ParentOrModule
          [debug] Found [name] of type [String] in scope Local
    [debug] Generated code: new SomeClass(name), Apply(Select(New(Ident(com.softwaremill.macwire.WorkpadApp.SomeClass)), termNames.CONSTRUCTOR), List(Ident(TermName("name"))))
    [success] Total time: 2 s, completed Feb 1, 2018 3:10:05 PM
    dvirf
    @dvirf
    @adamw thanks for your patience.
    Can you please clone https://github.com/dvirf1/play-samples and inside compile-time-di-macwire open sbt shell and run compile?
    You can see in the commit that i basically just added the scalacOptions and removed unused imports from the routes.
    Adam Warski
    @adamw
    @dvirf sorry, but I don't want to go into debugging some large pieces of code. It would be great if you could create a small, isolated test case and submit it as part of an issue.
    dvirf
    @dvirf
    @adamw see scala/bug#10579 and scala/bug#10571.
    I fixed it by adding -Ywarn-macros:after to the scalacOptions.
    It compiled for you since you used scala 2.12.3 and not 2.12.4.
    Adam Warski
    @adamw
    @dvirf ah, mystery solved - thanks for writing! Maybe you could add this to MacWire's README as well? Could help others in the future :)
    dvirf
    @dvirf
    @adamw in which section?
    Maybe under Installation, using with SBT at the end of the section (since users can add scalacOptions += "-Ywarn-macros:after” to the build.sbt)?
    Adam Warski
    @adamw
    sounds good!
    @dvirf ^
    fogfish
    @fogfish
    I am reading about "qualifiers"... "For that purpose Macwire includes support for tagging via scala-common..." I am just curious is wiring designed to work only with this tagging? Does it works/supports tagging from shapeless?
    Adam Warski
    @adamw
    @fogfish no, any kind of tagging will work; the one from softwaremill-common is simply the most bare-bones tagging that you can get, with nothing else in there
    as long as the types are distinct you are good :)
    fogfish
    @fogfish
    thank you
    Andrey Ivanov
    @a-nigredo
    Hi all, How macwire share instances between annotation? I mean e.g. @Module. Is it just an object with map inside?
    Adam Warski
    @adamw
    @a-nigredo it depends on how the instances are defined. If it's a val/lazy val, then the instances are shared. The wiring is just simple syntax sugar for creating new instances, so the instances are created and shared according to usual Scala rules, just as if the new ... was there
    Glen Marchesani
    @fizzy33
    I was trying to get a working demo app w/scala js (latest + scala 2.12). Any suggestions? I am not seeing any sjs build artifact in the various repos, which I was expecting to see....
    Adam Warski
    @adamw
    @fizzy33 the core of macwire is a macro, it's only used at compile time, so you can just depend on it in the usual way, no special artifacts needed
    Glen Marchesani
    @fizzy33
    @adamw thanks
    Glen Marchesani
    @fizzy33
    ah I see that "just works (tm)"... thanks again
    i.e. adding
    libraryDependencies ++= Seq(
      "org.scala-js" %%% "scalajs-dom" % "0.9.1",
      "com.lihaoyi" %%% "scalatags" % "0.6.5",
      "be.doeraene" %%% "scalajs-jquery" % "0.9.1",
      "org.scalactic" %%% "scalactic" % "3.0.1",
      "com.beachape" %%% "enumeratum" % "1.5.8",
      "in.nvilla" %%% "monadic-html" % "0.3.2",
      "a8" %%% "manna-sjs" % mannaVersion,
      "org.scalatest" %%% "scalatest" % "3.0.1" % "test",
      "com.softwaremill.macwire" %% "macros" % "2.3.1",
    //  "com.softwaremill.macwire" %%% "macros" % "2.3.1"
    )
    adding macwire as a regular old non-scala-js dep... somehow I was locked into thinking all the scala js deps had to be scala js builds
    John Menke
    @jmjava
    We have a lagom application that needs to initiate some bootstrap logic once macwire is done wiring the components. Is there a way to hook into this event?
    Adam Warski
    @adamw
    @jmjava there are no events as you would know them from "traditional" DI frameworks, but you can simply run the code after the object graph is created. If you are using lazy values and the startup depends on some of those, they will necessarily be created before the startup is ever run.
    Harmeet Singh(Taara)
    @harmeetsingh0013
    Hey Team, I am trying to inject Actor depedency with in normal scala class, But getting the error. Cannot find a value of type: [com.softwaremill.tagging.@@[akka.actor.ActorRef,harmeet.configuration.ControllerRef]] any one have any idea?
    Harmeet Singh(Taara)
    @harmeetsingh0013
    THis issue is resolved, actually, there are two actors systems are avialable, that's whyn getting the error
    Paweł
    @Garnek20_gitlab
    Hey guys, is it possible to wire a class dependent on the type that is suppose to deliver implicit of cats effect type classes within itself eg: class Example[T[_] : Effect : ContextShift](...) ? So far I'm getting not enough arguments... . I've tried to do it by implicit types and by implicit params, both approaches failed
    Alexey Novakov
    @novakov-alexey
    Hi there. if I use wired.lookup, can I get some meta info, whether instance was wired by MacWire or it manually with new? In my test, I need to know wether MacWire was actually used.
    Hi @Garnek20_gitlab , I do smth like this, not sure if it is your case:
    class MyModule[F[_]: Async: ContextShift] {}
    
    implicit val cs: ContextShift[IO] = IO.contextShift(global)
    val mod = wire[MyModule[IO]]
    Adam Warski
    @adamw
    @novakov-alexey no, as wire is a macro, it generates code, so in the compiled version it is (or at least should) be identical as if you wrote the code by hand. So a wire[T] invocation becomes new T(...) at compile-time
    Alexey Novakov
    @novakov-alexey
    yeah, this confirms the spec in README :-(
    ok, thanks @adamw
    Felix Palludan Hargreaves
    @hejfelix
    Importing a member from my config class causes this weird error:
    Found multiple values of type [io.clutchpower.pancakes.config.S3Config]: [List(copy$default$2, s3)]
    Adam Warski
    @adamw
    @hejfelix I guess you'd have to provide some more code to be able to say why this happens :)
    Johannes Ebbighausen
    @johannes-ebbighausen

    Hey all,
    I'm working on a Play-application. And I wired my userservice like this

    lazy val userService: UserService = wire[UserService]

    and the userservice is injected into any class

    class X(val userService: UserService)

    but how can I inject the userService into an object or a trait?

    object MyValidator { def isUnique(username: String): Boolean = userService.findBy(sqls.eq(userDao.s.username, username)).isDefined
    }
    Adam Warski
    @adamw
    you need to make MyValidator parametrised itself, if you want to sue the dependency
    so class MyValidator(userService: UserService)
    @johannes-ebbighausen ^
    Johannes Ebbighausen
    @johannes-ebbighausen

    thx @adamw So what about traits, I can only mixin the dependency in an implementing class right?

    trait X {
    val userService: UserService
    }
    
    class Y(_userService: UserService) extends X {
    override val userService = _userService;
    }

    whould be nice if there is a way to inject the dependency right in the trait.