0

I currently have a generic Azure repository AzureRepository<TEntity> store internally a list of table transaction actions like so.

private readonly IList<TableTransactionAction> tableTransactionActions;

The generic repository implements CRUD methods like this..

public void Delete(TEntity entity)
{
    tableTransactionActions.Add(new TableTransactionAction(TableTransactionActionType.Add, entity));
}

public void Insert(TEntity entity)
{
    tableTransactionActions.Add(new TableTransactionAction(TableTransactionActionType.Add, entity));
}

IUnitOfWork abstraction

public interface IUnitOfWork : IDisposable
{
    int SaveChanges();        

    Task <int> SaveChangesAsync();

    bool BeginTransaction();

    bool Commit();

    Task <bool> CommitAsync();

    void Rollback();
}

Question

Would you expose the internal list of TableTransactionActions to the unit of work to perform a commit, or rollback in a batch? How would you properly implement repository/unit of work to perform batched CRUD updates (not read of course)? Properly is subjective of course, however, I am looking for an answer that is well supported and makes a lot of sense in the context of Azure.Data.Tables SDK. Feel free to give direction instead of directly answering the question

I am open to creating more layers of abstractions as well like IDataContext.

Assume that I have a mechanism for retrieving repository instances of any type within the IUnitOfWork

2
  • 2
    Assuming you are trying to use the SubmitTransactions on TableClient (docs.microsoft.com/en-us/dotnet/api/…)... Unlike Relation DB transactions ... TableClient doesn't have a concept of BeginTransaction, Commit and Rollback. The TableClient.SubmitTransaction does either the 'commit' or 'rollback' itself. So, the IUnitOfWork implementation is not applicable here. The IList<TableTransactionAction> itself kind of acts like a 'unit of work' in this case. Regards Athadu Commented Jul 22, 2022 at 2:23
  • 1
    @Athadu This is true. There is no concept of begin, commit, and rollback in this SDK. A simpler, less abstract design seems best suited as you suggest. Commented Jul 22, 2022 at 3:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.