Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    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]
    but I get the following:
    trait Function1 is abstract; cannot be instantiated
    except I'm registering with a factory, he shouldn't try to instantiate anything, right?
    Adam Warski
    @adamw
    I don't understand the last step
    lazy val locationLookup = wire[LocationLookup]
    what do you mean by "getting an instance"?
    the instance is created by createLocationLookup, no?
    @remiguittaut ^
    Remi Guittaut
    @remiguittaut
    yes
    I just meant accessing it from inside an object
    when I need it in a class, I just set it as param to the constructor to get it injected
    Adam Warski
    @adamw
    yes
    Remi Guittaut
    @remiguittaut
    but it doesn't work, I get this thing about Function1 being a trait
    Adam Warski
    @adamw
    because you are doing wire[LocationLookup] :)
    which can't work
    you should pass localtionLookup instance as a paramtere