all groups > dotnet distributed apps > january 2006 >
You're in the

dotnet distributed apps

group:

N-Tier Dilemma and Transaction


N-Tier Dilemma and Transaction BELIUS
1/31/2006 7:45:29 AM
dotnet distributed apps:
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
Re: N-Tier Dilemma and Transaction Michael Nemtsev
1/31/2006 6:32:49 PM
Hello BELIUS,

B> here is my situation.
B> When I developed my .NET 1.x application (required to be database
B> indipendent and n-tier) I created a structure like this:
B> - Presentation
B> - BusinessLayer
B> - DataModel (referenced in BusinessLayer and DataLayer to communicate
B> entities)
B> - DataLayer
B> DataLayer: n assemblies specialized for the database. MyDal.SQL.dll,
B> MyDal.Oracle.dll etc...
B>
B> DataModel: 1 assemblies with entities and collection
B> MyApp.DataModel.dll
B>
B> BusinessLayer: 1 assembly MyApp.Business.dll, with a method inside to
B> create and instance (Factory) of the specified datalayer class
B> reading from a web.config section the name of the assembly to load.
B> The method CreateInstance using Reflection load the class and return
B> an Interface of the specialized class.

Everything you need to do it call DAL methods. It's wrong to specify
what's DB instance of DAL to create

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

Perform action of creating required DAL instance on the DAL layer.

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

When you move logic creating component on DAL you avoid reflections

B> Another question is.
B> If my approch is right I would ask you all, How can I handle
B> transaction in
B> BLL?

That's exactly the problem you design leads.

B> Please help me....I am so confused

You need to build loosy coupled system, remove dependencies between layers
and evething will be fine :)

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch

Re: N-Tier Dilemma and Transaction BELIUS
2/1/2006 12:39:27 AM
Hi Michael,

thank you for your reply.
I didn't understan well when you say " Everything you need to do it call DAL
methods. It's wrong to specify what's DB instance of DAL to create".

It is true that I need just to call DAL method, but how can I call the right
DAL method without know it?
Do you have a little example that show me how to reach this behavior?

Thank you

[quoted text, click to view]
Re: N-Tier Dilemma and Transaction Michael Nemtsev
2/1/2006 4:21:29 AM
Let imaging that you have a OraDal and SQLDal data components. Each of these
components has an overrided GetCustomers() methods. You have a common
DataController component that will instantiate required DB component depends
on your configuration settings and delegate all your request.

Everyting BAL should know it's the GetCustomers() method

[quoted text, click to view]

---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/members/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Re: N-Tier Dilemma and Transaction BELIUS
2/1/2006 6:01:38 AM
Hi Michael,

That's perfect....however there are just a few problem with the behavior you
described.

I am ok with the centralized DataController that expose a method
GetCustomers(),
and I am ok that somewhere in the datacontroller I read the configuration
file to know which DAL (OraDAL, SqlDAL) should I use.
In this case the DataController should expose all methods of my DAL even if
I don't need to view them.

For example I could code something like this:

CustomerCollection collCustomer = DataController.GetCustomers()
CategoryCollection collCustomer = DataController.GetCategory()

instead of

CustomerCollection collCustomer = myCustomerController.GetCustomers()
CategoryCollection collCustomer = myCategoryController.GetCategory()

and I don't like to have a huge class that expose all the methods I need for
my applications. This class could grow up to infinite methods
However independently from which approch a person likes I cannot understand
how can I avoid reflection inside the DataController
in order to do not reference the DAL assemblies inside the project and
mantaining the DAL assemblies separated.

here is my sample code to allow you see my implementation.

[Common Interface IUser.cs - Assembly MyApp.IData.dll]

public interface IUser
{
User GetUser(int UserID);
}

[SQL DAL doUser.cs - Assembly MyApp.Sql.dll]

public class doUser : doBase, IUser
{
public User GetUser(int UserID)
{
//SQL SPECIALIZED CODE
}
}

[ORACLE DAL doUser.cs - Assembly MyApp.Ora.dll]

public class doUser : doBase, IUser
{
public User GetUser(int UserID)
{
//ORACLE SPECIALIZED CODE
}
}


[Factory User.cs - Assembly MyApp.Factory.dll]

public class User
{
public static EnterprisePortalSolution.IData.IUser Create()
{
string providerAssembly =
ConfigurationSettings.AppSettings["DataProviderAssembly"];
string className = providerAssembly + ".doUser";

return
(EnterprisePortalSolution.IData.IUser)Assembly.Load(providerAssembly).CreateInstance(className);
}
}


[Business Layer boUser.cs - Assembly MyApp.Business.dll]
public class boUser
{
public User GetUser(int UserID)
{

User user = new UnknownUser();

IUser dal = EnterprisePortalSolution.Factory.User.Create();

try
{
user = dal.GetUser(UserID);
}
catch(Exception ex)
{
throw;
}
return user;
}
}

At the end it seems to me like move the use of reflection from BLL to DAL.

And the transaction?


Anyway I like this discussion :)
AddThis Social Bookmark Button