kamal
kamal

Reputation: 759

domain service or method inside domain

I have two aggrgate Roots, BonusProgram and Advertiser. Now the rule is an advertiser can have only single bonus program at a time. Now to assign bonusProgram to advertiser, what should i do, Do i have method like this in Advertiser.

    public virtual void AssignBonusProgram(BonusProgram bonusProgram)
    {
        this.bonusProgram = bonusProgram;
    }

or do i create domain service and have method like this in

   public void SubscribeToBonusProgram(BonusProgram bonusProgram, Advertiser advertiser)
   {

   }

Upvotes: 2

Views: 130

Answers (1)

Dmitry
Dmitry

Reputation: 17350

Service would be an overkill in this case. Your business rule is already captured by the fact that your bonusProgram is not a collection.

... the rule is an advertiser can have only single bonus program at a time.

And your implementation tells me that it is possible for advertiser to have no associated bonus program. If this is not the case you can simply check for null and throw ArgumentNullException. Domain services are very often misused and it may be a good idea to first try to put logic in one of the entities or value types. And only use domain service if the logic does not belong conceptually to any entity.

Upvotes: 4

Related Questions