Transactions for C# objects?

前端 未结 8 801
青春惊慌失措
青春惊慌失措 2020-12-01 09:26

Just curious, is there any support for transactions on plain C# objects? Like

using (var transaction = new ObjectTransaction(obj))
{
  try
  {
    obj.Prop1          


        
8条回答
  •  独厮守ぢ
    2020-12-01 10:18

    And here again simple solution is not to allow your objects to get into invalid state in the first place. Then you don't need to roll anything back, you don't need to call "Validate" etc. If you remove your setters and start thinking about sending messages to objects to do something on internal data, rather then setting properties, you'll uncover subtle things about your domain, that otherwise you would not.

提交回复
热议问题