N-Tier Dilemma and Transaction

Hi all,

here is my situation.
When I developed my .NET 1.x application (required to be database 
indipendent and n-tier) I created a structure like this:


- Presentation
- BusinessLayer 
- DataModel (referenced in BusinessLayer and DataLayer to communicate 
entities)
- DataLayer 

DataLayer: n assemblies specialized for the database. MyDal.SQL.dll, 
MyDal.Oracle.dll etc...

DataModel: 1 assemblies with entities and collection MyApp.DataModel.dll

BusinessLayer: 1 assembly MyApp.Business.dll, with a method inside to create 
and instance (Factory) of the specified datalayer class reading from a 
web.config section the name of the assembly to load. The method 
CreateInstance using Reflection load the class and return an Interface of the 
specialized class.


This behavior allowed me and allow me to have the max flexibility in order 
to load different assemblies for the specified database without change 
nothing other than the web.config section

With .NET 2.0 I saw the framework have the factories and I would like to 
know if they can help me to build a good infrastructure like mine without the 
use of reflection manteing separeted the asseblies 

Reading around I saw that the DbProviderFactory is perfect if someone use 
embedded queries, but in my situation would not work. I mean. When I use 
MyApp.SQL.dll inside his methods I use stored procedure instead when I use 
MyApp.MySQL.dll I use query stored in the code.
So by the Factory implemented in the BLL I am able to create an instance of 
the right DAL without know what is the code running inside the methods of the 
DAL.

Another question is.
If my approch is right I would ask you all, How can I handle transaction in 
BLL 
I mean.
If in the business layer there is a method that require a transaction I can 
simply use the EnterpriseService so all databases call (DAL call) inside that 
method is under a transaction....but if I don't need EnterpriseService (due 
to overheap) I can use ADO.NET transaction and the only way I found (quite 
clear) is passing the transaction Object from the BLL to the DAL. Is it the 
right behavior or there are better way to implement it  If I use this method 
I require to pass a IDbTransaction because I don't know which DAL the BLL 
will create, right  And in general when I pass value from the BLL to the DAL 
I should always pass interface in this case 

Please help me....I am so confused


Answer this question

N-Tier Dilemma and Transaction

  • Biryukov Ilya

    Abstraction Layer:

    http://danutp.blogspot.com/



  • timseal

    If you have a requirement that the DAL stores the queries to be run in a non-generic format, then the DbProviderFactory pattern won't be sufficient. You should be able to get rid of the reflection code by implementing your own generic layer for the DAL store (abstract class(es) that defines a DAL type, then specific implementations for each back end type).

    For transactional support, you may be able to use System.Transactions, which provides similar support to EnterpriseServices, but without as much overhead for simple scenarios.



  • King_Xerxes

    Hi!

    Kindly edit to increase font size so that other can read it without magnifying glass and its always good to preview before posting.

    Thanx



  • N-Tier Dilemma and Transaction