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
    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
    you already have the instance created using wireWith
    Remi Guittaut
    @remiguittaut
    ok, how should I do then?
    Adam Warski
    @adamw
    same as every other parameter
    Remi Guittaut
    @remiguittaut
    yes in a class, but in an object?
    Adam Warski
    @adamw
    well if you want parameters you can't have an object
    Remi Guittaut
    @remiguittaut
    yes
    but I can access singletons registered in macwire from an object, can't I?
    Adam Warski
    @adamw
    there's no such thing as "registered in macwire"
    wire just creates a new instance
    or wireWith, same thing, just creates an instance
    now you can do with the instance whatever you want :)
    e.g. access from an object if that's needed
    and if the instance is of course accessible
    Remi Guittaut
    @remiguittaut
    ok, how do I access it?
    from an object
    Adam Warski
    @adamw
    well by name for example
    where's the locationLookup instance defined?
    Remi Guittaut
    @remiguittaut
    inside of the module
    Adam Warski
    @adamw
    well then you need an instance of the module
    but maybe an object is not what you are after, if you need it to access dynamic configuraiton
    if the module instance is dynamic in some way