In the book of Eric Evan's "Domain Driven Design" (which people often called "the best example for DDD") there are many examples of aggregate roots (mainly the domain models or objects), which is filled with a specific request.
Take the following example:
public Car : IAggregateRoot { public List<Wheel> Wheels { get; set; } public void ReplaceWheels(); }
To replace the wheel, I have to request a new set of wheels from GarageService, who himself collects wheels WheelRepository. In one scenario, I am a customer and owner / mechanic garage, which replaces the wheel, so it is natural to call:
myCar.ReplaceWheels();
My question: Is it right to enter WheelService dependent on the aggregate root? Or should I say only WheelService?
public class MyCar : IAggregateRoot { private readonly IWheelService _wheelService; public List<Wheel> Wheels { get; set; } public MyCar(IWheelService wheelService) { this._wheelService = wheelService; } public void ReplaceWheels() { this.Wheels = _wheelService.getNewSet(); } } ; public class MyCar : IAggregateRoot { private readonly IWheelService _wheelService; public List<Wheel> Wheels { get; set; } public MyCar(IWheelService wheelService) { this._wheelService = wheelService; } public void ReplaceWheels() { this.Wheels = _wheelService.getNewSet(); } }
or
myWheelService.getNewSet(Car car);
source share