Transactions for C# objects?

前端 未结 8 764
青春惊慌失措
青春惊慌失措 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:06

    For what its worth, a full-blown STM is a little ways out, and I would strongly recommend against rolling your own.

    Fortunately, you can get the functionality you want by carefully designing your classes. In particular, immutable classes support transaction-like behavior out of the box. Since immutable objects return a new copy of themselves each time a property is set, you always have a full-history changes to rollback on if necessary.

提交回复
热议问题