Changing the signature of the method will be breaking everyone using it and creating an overload is IMHO a bit much. What I wonder is: the Func passed in can be pointing to anything: in your case the func likely calls a method which gets the UoW passed in and does the serialization. Why not let that method collect the errors too? Or do something like the following. ErrorCollector
here is a class name I made up, it can be anything.
// committing the datascope
var myErrorCollector = new ErrorCollector(); // class you write
Func<IUnitOfWorkCore, CancellationToken, Task<bool>> commitFunc = async (u, c) => await MyCommitMethodAsync(u, c, myErrorCollector);
var result = await myDataScope.CommitChancesAsync(commitFunc, CancellationToken.None);
//...
// the method which commits the work
public async Task<bool> MyCommitMethodAsync(IUnitOfWorkCore uow, CancellationToken cancellationToken, ErrorCollector collector)
{
// do your serialization and commit
//...
// result contains whether it was a success or failure
return result;
}
So the error object is embedded in the func call. This is similar to returning the instance of ErrorCollector from the func.