Thursday, November 18, 2004

.NET Transactions in Multi Tier ?

I want to discuss some more helpful issues related to NTier .NET Application Development. The latest one is..

Which is the best and prefered place to initiate the Transaction in .NET Multi Tier Application.

1. It should be handled in Database Layer with ADO.NET built in transaction management.
2. It should be start from the business layer as most of the times transacion process is some sort of business procss rather than database process.

3. If we start transation from the business layer then what is the best approach.

Hope most of them will come with some good arguments about this important issue of Multi Tier Applications.

Moderator (pakistan_dotnet)

My response:

1. Database Layer:
I will say a big no for this. Because not only these transactions are business processes, usually, but also at times they may span more than one database. So to say, if your transactions span multiple databases and/or are long running processes then database layer level transaction handling is almost out of the question. However for small apps and simple transactions ADO.NET transactions can be the best and most efficient way of implementing transactions. By the way unless and until I am using COM+, all the transactions drill down to this layer for execution eventually!

2. Business Layer:
I usually implement Transactions in applications Business Layer. I do it because, I believe, this is the logical place where I should be implementing my business processes.

3. Business Layer Transactions: Best Approach:
If I am using some application framework then I will make sure that my framework provides me the support of encapsulating transactions in Business Layer(similar is the case with DAL). We usually have a Manager (for CRUD and other related functionality) class for each domain entity and then based on requirements we also have enterprise managers for some of our entities, these enterprise managers inherit from some base class in our application framework which in turn implements IServicedComponent of System.EnterpriseServices. In this way COM+ support trickles down to our Business Logic Layer.
Even if you don't have such application framework then you can do the transactions your own way in BLL.

No comments: