|
|
Want to know more about Packt's Article Network? Interested in contributing your article ideas? Please visit our FAQ for more information. See More BROWSE
All Titles WordPress Web Services SOA BPEL Web Graphics & Video Web Development RAW Portugues, Espanol, Italiano, French PHP/MySQL Oracle Open Source Networking & Telephony Moodle Microsoft & .NET Linux Servers jQuery Joomla! JBoss Java e-Learning e-Commerce Dynamics Drupal CRM Cookbook Content Management Beginner Guides Architecture and Analysis AJAX Future Titles Recently Published Titles In this two-part article by Vivek Thakur, we will learn about ER Diagrams, Domain Model, and N-Layer Architecture with ASP.NET 3.5. The 1-tier 1-layer architecture is the default style in ASP.NET and Visual Studio 2005/2008. To overcome the limitations of this style, we can further break the application code into n-layers, where the number "n" actually depends on the project requirements. In this article we will:
See More |
ER Diagrams, Domain Model, and N-Layer Architecture with ASP.NET 3.5 (part2)
This is the second part of two-part article by Vivek Thakur on N-Layer Architecture with ASP.NET 3.5. In the first part we saw the need for a 3-layered solution and examined ER-diagrams, domain models and UML. In this part we will we will explore a 1-tier 3-layer Architecture using a Domain Model and Object Data Source Controls. 1-tier 3-layer Architecture using a Domain ModelBased on the class diagram in the first part, we will create a new simple 3-layered application using the entities defined in the above domain model. We will create a new ASP.NET Web Project in VS. This time, you should create two new folders inside your root web folder (using the Add New Folder option in VS):
Layer 1: Data Access Layer (DAL)First, we will create a DAL class for each entity. We will name each DAL class using this naming pattern: EntityDAL. Let us see the CustomerDAL class: using DomainModel.BL; Here, we have used the SqlHelper class, which contains generic data access utility methods, so that we can avoid code repletion. Layer 2: Business Layer (BL)Next, we will create classes for each of the domain entities. We will put all of these classes under the new BL folder with this namespace: DomainModel.BL. Create a new C# class file named Customer.cs under the BL folder. Here is the first Customer class: using DomainModel.DAL; The CustomerDAL class is pretty simple: we are fetching the data from the database using data readers, and performing all data related operations using the Customer business object. This Customer class is defined in the Customer.cs class we created earlier. This BL class is calling DAL methods, so it needs a reference to the DAL namespace (using DomainModel.DAL). Similarly, the DAL class we created earlier used Customer business objects. That's why it also needed the BL namespace. We are using generics to create a collection of Customer objects. The BL communicates with DAL to get the data and perform updates. Now, we will see how the UI (which is under a different namespace) talks to BL without even knowing about DAL. Layer 3: The UI LayerHere is the code in the AllCustomers.aspx.cs page that shows a list of all of the customers from the DB (there is a data list on the web form, which will show a list of the customers): using DomainModel.BL; So in the UI class, we neither have any data access code nor are we calling data access class methods from this layer (as was the case with the 1-tier 2-layer style we saw earlier in this article). We have a reference to the BL layer (using DomainModel.BL), and we are using the Customer business object to return a generic list of customer objects, which we are binding to the data list control (showing a list of all the customers). So the GUI layer does not know anything about the DAL layer, and is completely independent of it. The idea here is to understand how a 3-Layer architecture can provide more flexibility and loose-coupling to your project. In the next section, we will learn how we can use object data source controls to implement a 3-layer architecture without writing much code ourselves. ASP.NET 3.5 Application Architecture and Design
Object Data Source ControlsData source controls can replace the data access code but they tightly couple the GUI to the data methods. To overcome this problem, Microsoft introduced object data source controls, so that we can bind directly to business objects, making it possible to use them in a 3-tier architecture. Let's see how using object data source controls will shape our application:
As we can see, using object data source controls complements the domain model and helps us avoid writing the UI layer code, as we can directly bind custom entities to data-bound controls in UI. However, there are a few issues in using object data source controls:
Reflection is a technique which VS uses to get metadata information about other entities, such as a class file or an assembly. Using reflection, the object data source control will first "read" the class to get all of the attributes and then use this metadata to connect to and perform operations on the class. On account of this additional "reading" step, the application suffers a performance hit. Therefore, for a flexible approach, it is best to use custom code. But for small projects where we don't foresee any major complexity and performance issues, object data source controls are a good option to save on development time while supporting a flexible n-layer option. SummaryAll of the samples we covered in this two-part article were of the 1-tier n-layer style. We learned how to create a 1-tier 2 layer architecture using logical code separation. Then we focused on the need for a 3-layered solution and examined ER-diagrams, domain models and UML, all of which are important tools that aid in the understanding of commercial projects required to build a 3-layered structure. We then focused on a 3-layered application structure for OMS, and looked at how both custom code and object data source controls can be used in this architecture. If you have read this article you may be interested to view : ASP.NET 3.5 Application Architecture and Design
About the AuthorVivek Thakur is passionate about architecting and developing applications based on Microsoft .NET platform using ASP.NET, C#, VB.NET, and MS AJAX. He has authored several technical articles on ASP.NET and has also been an All-Star-level contributor on ASP.NET forums. Vivek’s passion for ASP.NET has been formally recognized by the Most Valuable Professional (MVP) award given to him by Microsoft in April 2007, and again in 2008. He is also a Subject Matter Expert for Microsoft ASP.NET 3.5 Certification Exams. He is a leading contributor and moderator in the CodeAsp.Net forums. Vivek is currently working as the Managing Partner in Axero Solutions LLC, a US-based software product development and business consulting firm Although his expertise lies in Microsoft's .NET platform, Vivek is also knowledgeable in J2EE and C/C++. He has a deep interest in programming, chaos theory and artificial intelligence, and is a strong advocate of chaos theory in software systems and management. Besides his love for software architecture and design, Vivek also focuses on project management skills and has substantial experience in managing small to medium sized projects. He has also conducted numerous training sessions and provided concept-based tutoring in different software firms across India. Vivek received his Bachelors degree in engineering from the Indian Institute of Technology (IIT), New Delhi, India. Books from Packt
|
These days, Model View Controller (MVC) is a buzzword in the ASP.NET community, thanks to the upcoming ASP.NET MVC Framework that Microsoft is expected to launch soon. The Framework allows easier adoption of the different MVC patterns in our web applications.In this article by Vivek Thakur, we discuss ASP.NET MVC Framework in detail with the help of a Sample Project. We also take a glance at Unit Testing with reference to ASP.NET MVC Framework. The ASP.NET MVC framework was released by Microsoft as an alternative approach to webforms when creating ASP.NET based web applications. The ASP.NET MVC framework is not a replacement or upgrade of webforms, but merely another way of programming your web applications so that we can get the benefits of an MVC design with much less effort. See More |
| ||||||||