should service layer methods wrapped inside a transaction? RRS feed

  • Question

  • Hi,

    In domain driven design,assuming i have a domain model, a repository and a service layer

    Shouldn't each  service method wrapped  inside a transaction? or better use declarative transactions?

    The reason is that if lower layer changed there might be a need to call it from a transaction

    Even a simple change like changing the object mapping from single table to several tables can

    Create needs for transaction, (assuming the OR mapper dont  handle it, which is a disaster…)


    Friday, January 15, 2010 9:58 PM


  • IMHO the answer is yes.  I am not so much talking about the specifics of domain driven design and other specifics of your example, but simple from the perspective that a service layer can make calls to multiple business layer objects that themselves can perform multiple database operations.  In such scenario you would need to a higher level transaction to oversee a transaction across multiple database calls, something along the lines of a TransactionScope.  I am guessing there are better solutions with something declarative, perhaps a container of sorts.
    • Marked as answer by אורצ'וק Wednesday, January 20, 2010 10:03 AM
    Wednesday, January 20, 2010 2:53 AM