smotastic / smartstruct

Dart Code Generator for generating mapper classes
35 stars 20 forks source link

Add lifecycle methods (after & before) #77

Open DenisBogatirov opened 1 year ago

DenisBogatirov commented 1 year ago

It would be very helpful to have annotations for BeforeMapping & AfterMapping like the original mapstruct has.

Example usage:

class Source {}

class Target {
  Service _service;

  void setSevice(Service service) {
    _service = service;
  }
}

@Mapper()
abstract class SourceToTargetMapper {
  Service _service;

  SourceToTargetMapper(Service service) {
    _service = service;
  }

  Target fromSource(Source source);

  @AfterMapping()
  void afterMapping(Target target) {
    target.setService(_service);
  }
}
smotastic commented 1 year ago

Hi, like the idea a lot, should also be relatively easy to implement