macwire icon indicating copy to clipboard operation
macwire copied to clipboard

wire all implementations of given base trait/class

Open pawels84 opened this issue 6 years ago • 0 comments

building on the example of multi-wiring via wireSet would it be possible to achieve this:

trait Musician
class RockBand(musicians: Iterable[Musician])

class Singer extends Musician
class Guitarist extends Musician
class Drummer extends Musician
class Bassist extends Musician

trait RockBandModule {

  lazy val musicians: Iterable[Musician] = wireAll[Musician] // all above musicians classes will be instantiated

  lazy val rockBand  = wire[RockBand]
}

namely: have a wireAll[Base] method to instantiate all non-abstract classes derived from Base

it would be handy not to have to list all implementations (as in the wireSet example) of given trait and have it wired automatically so in case you add more implementations they will be added to the collection without any modifications to the module code

pawels84 avatar Feb 01 '19 14:02 pawels84