Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Marius B. Kotsbak
    @mkotsbak
    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
    Marius B. Kotsbak
    @mkotsbak
    A workaround is to use a cake here instead. It compiles if I let DatabaseSetupAndTeardown inherit from TestModule, but then I don't use MacWire...
    Adam Warski
    @adamw
    I'm not sure what's the full example, but macwire only helps you to wire classes using constructor parameters
    it's mostly a convenience tool so that you don't have to write the constructor call yourself
    Marius B. Kotsbak
    @mkotsbak
    Yes, but shouldnt the wire macro work too?
    Mark Grey
    @DeaconDesperado
    I'm probably misunderstanding macwire in a very simple way, but if i have a collection of "interfaces" represented as traits, and want to "wire" the implementation of those traits in (think like guice here I guess?), how would that work with macwire? If I'm understanding the example in the README correctly it seems to be wiring only the implementations themselves.
    Rafal Wachol
    @charafau
    you simply wire implementation like wire[DatabaseDaoImpl]
    in tests you can make TestModule which will extend MainModule and override that wire with some MockDatabaseDao
    Greg Silin
    @gregsilin
    Howdy.. is there a way to make circular dependencies work with macwire? I'm on macwire 1.0.x, Scala 2.11, Play 2.3.x although I could upgrade to macwire 2.x if necessary. In my case, I have service A depend on service B & service B depend on service A, so I would expect other people have hit this situation. Assume that in my case it's a large codebase and I can't quite refactor to remove those cases
    Greg Silin
    @gregsilin
    Solution hinted at here fixed the issue for me adamw/macwire#18
    will appreciate suggestions on better approaches, if there are any
    Joseph Price
    @joprice
    what do you consider the best practice for disambiguating primitives used to configure a service with macwire? (tagged types, value classes, wrapper objects representing a group of config fields, etc)
    Adam Warski
    @adamw
    @joprice macwire or not, I would say that getting more type-safety is usually beneficial, esp when there are many primitives around :) All three options you mention have different use-cases, e.g. type-tagging has the benefit that you can use any existing type as a tag so I've used that to tag the Long id of an entity with the type of the entity. Otherwise I'd say some kinds of wrapper objects
    Joseph Price
    @joprice
    Thanks! I came to the same conclusions but wasn’t sure if you had come up with other patterns I wasn’t yet aware of.
    Marius B. Kotsbak
    @mkotsbak
    How to override a single dependency with a mock in the tests?
    Marius B. Kotsbak
    @mkotsbak
    I.e I have a module with all deps setup, but I want to override it with some local dependency that is a mock
    Adam Warski
    @adamw
    if the module is e.g. a trait, just override that single dependency
    Marius B. Kotsbak
    @mkotsbak
    Hmm
    I have the test class extended from the module trait
    I guess it is impossible to override it for just one test then as the wiring happens at compile time
    Adam Warski
    @adamw
    right, then you have to instantiate the module trait for each test
    which kind of makes sense, as you want a different dependency for each test in your scenario
    Marius B. Kotsbak
    @mkotsbak
    Will try
    Marius B. Kotsbak
    @mkotsbak
    Seems to work fine to just make an anonymous class overriding for mocking from the module in each test
    Marius B. Kotsbak
    @mkotsbak
    Does Macwire support injecting a function?
    Adam Warski
    @adamw
    Sure, any Scala type
    function is not special in any way :)
    Marius B. Kotsbak
    @mkotsbak
    Ok, we got a syntax error here
    Marius B. Kotsbak
    @mkotsbak
    It was something about not being able to instanciate it using DI with wire[] because it was abstract
    Adam Warski
    @adamw
    but it works now or you are still having problems?
    Marius B. Kotsbak
    @mkotsbak
    It still fails with that aproach, but it is in a coworker's code
    Adam Warski
    @adamw
    well, if you have some short example, paste it here, maybe somebody will spot something :)
    Remi Guittaut
    @remiguittaut
    Hi, I'm the Coworker
    I declare my functions types that way: type LocationLookup = xxx => ExecutionContext => OptionT[Future, Location]
    then I've got a factory:
    def createLocationLookup(locationManager: LocationManager): LocationLookup = xxx => { implicit ec: ExecutionContext => OptionT(locationManager.getLocation(xxx)) }
    I register this function my module this way:
    lazy val locationLookup: LocationLookup = wireWith(Lookups.createLocationLookup _)
    and, inside of an object, to get an instance:
    Remi Guittaut
    @remiguittaut
    lazy val locationLookup = wire[LocationLookup]