Building an N-Tier Architecture Application in Silverlight 4 Part I

Vuyiswamb
Posted by in Silverlight category on for Beginner level | Points: 250 | Views : 10408 red flag

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.

Authors Preface

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.  

http://www.codeproject.com/KB/cs/N-Tier22.aspx?msg=2623413#xx2623413xx






And the Following Screen-shot, shows the first interaction between me and Sheo Narayan (Dotnetfunda Founder)



Introduction

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.

 

Background

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

Using the code

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.

Start

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.

Presentation Layer

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 nothing else.

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 a web application, you would probably use Jquery or pure JavaScript to trap for 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.

Data Layer

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

http://weblogs.asp.net/pgielens/archive/2008/11/03/best-decision-to-kill-linq-to-sql.aspx

http://weblogs.asp.net/pleloup/archive/2008/12/01/is-linq-for-sql-truly-dead.aspx

http://ayende.com/Blog/archive/2008/10/31/microsoft-kills-linq-to-sql.aspx

 

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 things. 

 

Road-map

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.

 

Conclusion

 This 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.

Thank you for visiting Dotnetfunda

Vuyiswa Maseko


Page copy protected against web site content infringement by Copyscape

About the Author

Vuyiswamb
Full Name: Vuyiswa Maseko
Member Level: NotApplicable
Member Status: Member,MVP,Administrator
Member Since: 7/6/2008 11:50:44 PM
Country: South Africa
Thank you for posting at Dotnetfunda [Administrator]
http://www.Dotnetfunda.com
Vuyiswa Junius Maseko is a Founder of Vimalsoft (Pty) Ltd (http://www.vimalsoft.com/) and a forum moderator at www.DotnetFunda. Vuyiswa has been developing for 16 years now. his major strength are C# 1.1,2.0,3.0,3.5,4.0,4.5 and vb.net and sql and his interest were in asp.net, c#, Silverlight,wpf,wcf, wwf and now his interests are in Kinect for Windows,Unity 3D. He has been using .net since the beta version of it. Vuyiswa believes that Kinect and Hololen is the next generation of computing.Thanks to people like Chris Maunder (codeproject), Colin Angus Mackay (codeproject), Dave Kreskowiak (Codeproject), Sheo Narayan (.Netfunda),Rajesh Kumar(Microsoft) They have made vuyiswa what he is today.

Login to vote for this post.

Comments or Responses

Posted by: Karthikanbarasan on: 2/8/2011 | Points: 25
Hi,

Nice article... Can you guide me on how to start with silver light... Im new to that and i want to learn
Posted by: Vuyiswamb on: 2/8/2011 | Points: 25
Good Day Karthikanbarasan

I will be realizing Part 2 of this article in few days, and it will take you step by Step. For now get Ready and collect the Tools as Explained in this article
http://www.dotnetfunda.com/articles/article1074-how-to-send-an-email-in-silverlight-part-1-.aspx

Look at the Table it has links to the things you need to Run or develop Silverlight Apps
Posted by: Ranavishnu on: 5/24/2012 | Points: 25
hi,

good start for n-tier silverlight application, but where is 2nd article??
Posted by: Vuyiswamb on: 5/24/2012 | Points: 25
I did not have enough time, in fact i did not write any article this year, i still need some free time to continue this series.
Posted by: Mukuwa on: 10/18/2013 | Points: 25
where is
Building an N-Tier Architecture Application in Silverlight 4 Part II,III and IV?
Posted by: Vuyiswamb on: 10/18/2013 | Points: 25
Hi mukuwa. Time is no longer on my side. I try to write but time is a bit limited

Login to post response

Comment using Facebook(Author doesn't get notification)