This is my first part of the series of N-Tier architecture in Silverlight. I would like to stress that the architecture has been misused and abused. I came across designs that were breaking the rules of the N-Tier architecture designs. We will highlight those rules in the series of this subject. Microsoft did a good job with Silverlight, there is no way of adding inline or naked SQL statements in the Presentation Layer anymore, like it used to be in Asp.net and win forms applications I have ever came across. As an N-Tier architecture evangelist I always practices what I preach everywhere I go.
I know this is the strangest way of starting an article, but I want you to know who is writing the article, where does he come from with this idea and what did the people thought about his writings in those days and how is he going to keep his promises to his readers.
And the Following Screen-shot, shows the first interaction between me and Sheo Narayan (Dotnetfunda Founder)
This is my first part of the series of N-Tier architecture
in Silverlight. I would like to stress that the architecture has be misused and
abused. I came across designs that were breaking the rules of the N-Tier
architecture designs. We will highlight those rules in the series of this
subject. Microsoft did a good job with Silverlight, there is no way of adding
inline or naked SQl statements in the Presentation Layer anymore, like it used
to be in Asp.net and win forms applications I have ever came across. As an
N-Tier architecture evangelist I always practices what I preach everywhere I go.
In this Article I am going to explain
clearly on how to use N-Tier architecture and the benefits of it. The Examples
here will be presented in Silverlight and SQL
We are going to use C# as our main
Language for example code and you can use any version of SQL for the Database.
But in Part 1, there won’t any code that will be written.
First I will start and
prepare you for the journey on the Series.
What is N-Tier Architecture?
N-Tier is pattern that you use to
construct your application. It is an architecture that separates the
Application in many parts that are connected no matter where the parts are
located. I will highlight the most important parts of this architecture.
This is the user Interface. This is what
the user is interacting with, and this is called the “Presentation Layer”,
because it is presented to the user. This Layer does not contain any SQl
Statements and it has no Knowledge that there is a Database. It only knows that
there is a Layer that is called the “Business Logic Layer” and it does not know
where the Business Logic Layer gets the Data and for a matter of fact, it does
not care as long as it gets the Data or objects.
Business Logic Layer
This is the most important Layer in this architecture.
Again this is the most misused layer. The main purpose of this layer is to make
sure that the business rules are not violated. But what are the business Rules?
These are things like “if age is less
than 18 don’t allow the user to register” these are the business rules and
In this Layer we also make sure that the Data that will be passed
to the Data Layer is clean, it is what the next Layer expect. In windows
applications some programmers might decide to trap the age in the presentation layer
and that is still good because it does not break the rules. If you are building
such things on the client-side.
To conclude, this layer is the only Layer that
accesses the Data-layer and it has no knowledge on where “Data Layer” gets the
Data and it does not care. One more thing I must mention is that exceptions are
caught at all layers and they are logged into the Database on all layers
because there might be different types of exceptions that might occur on different
levels on these layers. I will not go deeper on the Exception handling because
it is beyond the scope of this article.
In this Layer we call the stored procedures. I am against writing SQl statements
on this layer. I prefer to call stored-procedure than writing my SQl statements
(Naked SQL or Inline) here. In fact when
Linq to SQl was introduced, I was against the idea. Because you would write some
SQl in Linq on the Data-layer.
There were some code generation happening there
and I hated wizards (Code Generation). For me it did not change the fact that
those were SQl statements. SQL Server is
good in Database work, let the SQL Server handle the Database and let the .Net framework
handle the non-database stuff.
I was not
surprised when Microsoft stopped working on Linq (2008). What they said was
they will not continue to work on Linq because it is not in the future plans or
it’s not in their development road-map, but they will enhance it based on the
community feedback. http://blogs.msdn.com/b/adonet/archive/2008/10/29/update-on-linq-to-sql-and-linq-to-entities-roadmap.aspx .
What other People’s thoughts on this
And after that there was MVC pattern J , and Expression
Studio. Basically Microsoft was saying Let the SQL do the database work, Let
the designers work independently on the presentation Layer and do what they do
best, let C#, Vb.net do what it does best on the .NET Framework. As you can see the plan was to separate these
To those who used to read my articles, you will
notice that this diagram above looks familiar. This diagram shows what I wrote
about the layers. Please note that I don’t regard the SQl server as a Layer.
I think I should not overload you with a lot of
information in this part 1 of this series, I will not write any code, I just
want to you to grab the concept before we start getting our hands dirty.
was part 1 of the series. In the next article we are going to construct our
layers and follow some best practices that I will demonstrate to you. To those
who were waiting for this series, you will not wait any longer.
for visiting Dotnetfunda