Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Adam Warski
    @adamw
    so it was the initialization order
    common with lazy vals :)
    Aleksandrov Vladimir
    @invis87
    indeed :)
    Aleksandrov Vladimir
    @invis87
    One more question ^^
    If I have a class (PostgreDB for example) that use DBPoolActor for operations. How can I inject it?
    I can't write like this:
    class PostgreDatabase(dbPoolActor: ActorRef)
    because I have more than one Actors in my system that I want to inject
    Looks like I should use tags
    Aleksandrov Vladimir
    @invis87
    buuuuut I dont understand how use it properly
    I have:
    import play.api.Play.current
    import play.api.libs.concurrent.Akka
    
    trait ActorsModule {
    
      lazy val actorSystem = Akka.system
      lazy val dbPoolActor = actorSystem.actorOf(Props(wire[DBPoolActor])).taggedWith[DBPoolActor]
    }
    and DB
    class PostgreDatabase(dBPoolActor: ActorRef @@ DBPoolActor) extends Database { ...
    }
    But how my DatabaseModule should looks like???
    trait DatabaseModule {
      lazy val database: Database = ???
    }
    Aleksandrov Vladimir
    @invis87
    When I am trying
    lazy val database: Database = new PostgreDatabase(wire[ActorRef @@ DBPoolActor])
    I get error
    Compilation error[Cannot find constructor for WeakTypeTag[com.softwaremill.macwire.@@[akka.actor.ActorRef,actors.DBPoolActor]]]
    Aleksandrov Vladimir
    @invis87

    hmmm, looks like I understand :)

    trait DatabaseModule extends ActorsModule {
      lazy val database: Database = wire[PostgreDatabase]
    }

    this works fine

    Adam Warski
    @adamw
    :) yes, that's how you should use tags
    Erik LaBianca
    @easel
    are macwire builds for scala.js kept up to date? I’m seeing unresolved dependency: com.softwaremill.macwire#macros_sjs0.6_2.11;2.2.0: not found adding it with %%%
    Adam Warski
    @adamw
    I don't think there ever was a dedicated scala js build
    doesn't it work using just %%?
    Adam Warski
    @adamw
    @easel I just updated the scalajs example to newest of everything and I think it works fine with %%, no dedicated build neeeded, see: https://github.com/adamw/macwire/tree/master/examples/scalajs
    Erik LaBianca
    @easel
    Ah silly me. It’s compile-time only, I suppose so no %%% needed. Thanks =p
    Adam Warski
    @adamw
    hmm there are some runtime components as well, I'm not very familiar with scala-js , maybe these runtime would need to be published specially for scala-js
    Erik LaBianca
    @easel
    I’d expect the runtime stuff would need to be. If it’s not “known to work” I can pull down the sources and fiddle with it, it should be just a matter of publishing the cross build.
    Adam Warski
    @adamw
    @easel that would be great - I don't think it's "known to work". The runtime components are: util (no deps), and proxy, that however depends on javassist - I'm not sure if that would work in Scala.JS, but again, I didn't try :)
    Erik LaBianca
    @easel
    Ok sounds good. My hunch is that proxies in javascript would need to be handled differently. I’ll reach out here once I have a second to poke at it.
    Artyom Kozhemiakin
    @akozhemiakin
    Hi guys! I wonder if there is any automatic way to inject multiple dependencies implementing the same interface (extending the same trait) in a form of a List (or Set, or other collection, or even shapeless HList) using macwire? I'm talking about some functionality more or less similar to the multibinding in Guice
    Artyom Kozhemiakin
    @akozhemiakin
    Ok, it seems that I eventually encountered what I'v searched for in the source code and it is "wireSet" method. Also it is not documented and I'm not quite sure how to use it properly.
    Artyom Kozhemiakin
    @akozhemiakin
    I'v created the pull request to add HList injection support: adamw/macwire#88
    Ilya Epifanov
    @ilya-epifanov
    Hi guys, can I wire some parameters with macwire but provide remaining ones with implicits manually?
    Like this: def strategy1()(implicit staticsContext: StaticsContext, param1: Param1) = wire[Strategy1]
    class Strategy1 @Inject() (val service1: Service1, val service2: Service2)(implicit staticsContext: StaticsContext, param1: Param1) { ... }
    Or should I separate this into two classes?
    Ilya Epifanov
    @ilya-epifanov
    Ok, I've tested this, it works fine:)
    Rafal Wachol
    @charafau

    hello! I am doing some programming with scala on android and I thought about using macwire. Everything works nicely but I got stuck with injecting class which depends on the other one extending module. Example:

    class ChatPresenter(chatContractView: ChatContractView) extends ChatContractPresenter { }
    
    trait ChatModule {
      import com.softwaremill.macwire._
    
      lazy val presenter: ChatContractPresenter = wire[ChatPresenter]
    
    }
    
    class ChatFragment extends BaseFragment  with ChatModule { pesenter. ..... }

    So I want to use ChatPresenter in ChatFragment. How can I achieve this ?

    Rafal Wachol
    @charafau
    ok, I resolved my problem, in case someone will have the same problem, I'm leaving solution here:
    trait ChatModule {
      import com.softwaremill.macwire._
    
      def presenter(chatContractView: ChatContractView) : ChatContractPresenter = wire[ChatPresenter]
    
    }
    
    class ChatFragment extends BaseFragment
      with ChatContractView
      with ChatModule {
    
      val chatPresenter = presenter(this)
    }
    Marius B. Kotsbak
    @mkotsbak
    Hi
    Maybe a strange question, but as Macwire is at compile time, is it possible to DI types?
    Rafal Wachol
    @charafau
    what do you mean
    Denis Mikhaylov
    @notxcain
    Typelevel DI, sounds cool, even though I do
    Marius B. Kotsbak
    @mkotsbak
    I mean something like "type DB = PSQLProfile" where MacWire replaces PSQLProfile with the correct type that is later used directly
    Adam Warski
    @adamw
    @mkotsbak I'm not sure how that could work. Maybe you could paste a snippet which would demonstrate what you'd like to have?
    Marius B. Kotsbak
    @mkotsbak
    Will do
    In the mean time I got it to blow up completely: exception during macro expansion:
    [error] scala.reflect.macros.TypecheckException: not found: value actionBasedSQLInterpolation
    Marius B. Kotsbak
    @mkotsbak
    at com.softwaremill.macwire.TypeCheckUtil.typeCheckExpressionOfType(TypeCheckUtil.scala:58)
    Marius B. Kotsbak
    @mkotsbak
    Hmm, yes it is trying to DI some type I am supposed to declare myself
    Marius B. Kotsbak
    @mkotsbak
    @adamw I am still unsure how I get a lazy val to be picket up by MacWire instead of it trying to contruct the class manually
    Tried @Module
    Adam Warski
    @adamw
    @mkotsbak some simple snippet of what you are trying to do would be helpful :)
    Marius B. Kotsbak
    @mkotsbak
    Well, I see that it is needed to declare the dep using constructor parameters too, but what I have is a trait
    I'm struggeling with this one:
    DatabaseSetupAndTeardown.scala:30: Cannot find a public constructor nor a companion object for ...DatabaseProfile
    at lazy val dbProfile = wire[DatabaseProfile]
    Which is declared here:
    @Module
    trait TestModule extends BackendCoreModule {
        override lazy val dbProfile = H2TestProfile
    }
    But DatabaseSetupAndTeardown is a trait and can't be a class