Example of Domain Service
Looking at source code I could not found example of DomainService, i.e. for some volatile policy, or use case, involving several aggregates.
I am looking for how your IBusinessRule pattern should be implemented there. In my experience DomainService also could generate BusinessRules-relates exceptions.
Hi @sm-g ,
Thanks for pointing this out, I agree that an example of Domain Service building block is needed. I will try to add something soon.
Hi @sm-g again,
We recently added example of Domain Service - please check SubscriptionDateExpirationCalculator.cs
public class SubscriptionDateExpirationCalculator
{
public static DateTime CalculateForNew(SubscriptionPeriod period)
{
return SystemClock.Now.AddMonths(period.GetMonthsNumber());
}
public static DateTime CalculateForRenewal(DateTime expirationDate, SubscriptionPeriod period)
{
if (expirationDate > SystemClock.Now)
{
return expirationDate.AddMonths(period.GetMonthsNumber());
}
return SystemClock.Now.AddMonths(period.GetMonthsNumber());
}
}
Hi.
For me this sevice does not contain expected complexity ("volatile policy, or use case, involving several aggregates") which should be covered by example.
Why these fucntions are not in SubscriptionPeriod VO itself? Looks like it is its "natural responsibility" - so there is no need for domain service here. (Another sign it that they are static methods and and this service has no dependencies.)