How to use transaction through multiple layer code in C#
Suppose my project is like .net petshop. It has a BLL, DAL and SQLHelper.
Normally, I call a BLL function in my web layer, and the BLL function
calls the DAL function and finally, the DAL call the sqlhelper.
But in some situations, I nedd a transaction.
For example:
Web layer:
I need Call some BLL functions. Code as below:
var m = BLLFunction_1();
var n= BLLFunction_2();
if (m+n<100)
{
// need rollback here
}
else
{
BLLFunction_3();
// commit here
}
So it makes me have to use a transaction object in the web layer, to pass
it into the BLL function, and BLL layer pass it into DAL layer, and
finally pass it into SQLHelper.
That's a little ugly.
I wonder what is a elegant methed to this situation.
No comments:
Post a Comment