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