Rich domain model with behaviours and ORM

前端 未结 4 1306
孤城傲影
孤城傲影 2021-02-02 13:54

After watching NDC12 presentation \"Crafting Wicked Domain Models\" from Jimmy Bogard (http://ndcoslo.oktaset.com/Agenda), I was wandering how to persist that kind of domain mod

4条回答
  •  悲哀的现实
    2021-02-02 14:06

    When doing DDD first thing, you ignore the persistence concerns. THe ORM is tighlty coupled to a RDBMS so it's a persistence concern.

    An ORM models persistence structure NOT the domain. Basically the repository must 'convert' the received Aggregate Root to one or many persistence entities. The Bounded Context matters a lot since the Aggregate Root changes according to what are you trying to accomplish as well.

    Let's say you want to save the Member in the context of a new offer assigned. Then you'll have something like this (of course this is only one possible scenario)

    public interface IAssignOffer
    {
        int OwnerId {get;}
        Offer AssignOffer(OfferType offerType, IOfferValueCalc valueCalc);
        IEnumerable NewOffers {get; }
    }
    
    public class Member:IAssignOffer
    {
        /* implementation */ 
     }
    
     public interface IDomainRepository
     {
        void Save(IAssignOffer member);    
     }
    

    Next the repo will get only the data required in order to change the NH entities and that's all.

    About EVent Sourcing, I think that you have to see if it fits your domain and I don't see any problem with using Event Sourcing only for storing domain Aggregate Roots while the rest (mainly infrastructure) can be stored in the ordinary way (relational tables). I think CQRS gives you great flexibility in this matter.

提交回复
热议问题