modular-monolith-with-ddd icon indicating copy to clipboard operation
modular-monolith-with-ddd copied to clipboard

Example of Domain Service

Open sm-g opened this issue 5 years ago • 3 comments

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.

sm-g avatar Apr 27 '20 12:04 sm-g

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.

kgrzybek avatar May 01 '20 17:05 kgrzybek

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());
    }
}

kgrzybek avatar Aug 21 '20 19:08 kgrzybek

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.)

sm-g avatar Aug 22 '20 05:08 sm-g