Introduce DataBase,Asp.net,JavaScript,Xml,Html,Css,Sql,Php,ASP.NET Controls,AJAX,Tools,HTML,CSS,JavaScript,Open Source Project,WPF,.Net Framework,Linq
Top Recommended Hosting

How to achieve layered approach in asp.net 2.0

by the3factory 5/10/2008 8:01:00 PM
Question:

ASP.NET 2.0 provided us with some rich controls like sqldatasource and other data presentation control that has speeded up the app development by writing less code. We simply need to drag and drop these controls onto the page and simply configure it with what database table to get data from; insert, update, delete commands are automatically created. Earlier we used to do this all programatically; creating connection object, command object, execute command and so on, so it was easy to work in layers keeping ppt, business and data layers separate.

How do we follow the layered approach while using new controls. These UI controls are so much attached to the database, how is it possible to have separation of concern. Because when working with large projects we need to have decoupled layers which makes maintenance easy rather than a nightmare. Anyone having experience with large projects and used these .net 2.0 control's smart features while implementing a layered architecture, please do give your views. And if there are any design patterns specific to this issue plz tell.

Thanks 

 

 


Answer1:

The Layered approach still remains the same. but now what you need to do is to have a vb class say gridsource,detailsource and blah blah...in App_code folder and the select command (can be stored procedure) can be accessed programmatically , Microsoft provides any functionaly does not mean that you have to use in that manner, you need to think on how to make it more manageable.Smile

Even i faced the same problem , but when get used to work in that fashion (vb class..) it obviosuly is a great way to do things.


Answer2:

I ran into the same issue when i was using the MVP pattern to keep my UI isolated from my page logic and had to use the gridview control, this control requires a datasource to bind to as you mention one of these is the SqlDataSource but as you point out this couples too closely to the database, to get round this and continue to use MVP at the time I used the ObjectDataSource and had to do some messing around to pass the presenter in. I think now I would look at the ObjectDataContainerSource object that the PnP group use with the WCSF this article should give you more details to go on http://www.pnpguidance.net/Post/ObjectContainerDataSourceGridViewASPNETModelViewPresenter.aspx

 Hope this helps 


Answer3:
There is also OjectDataSource yuou can use to provide data bound controls with objects from your BLL. Keeping direct databaqse queries in presentation layer is bad practice because presentation layer is then strongly dependent on all changes in DAL.

Answer4:

 Thanks pradeepbohra 

But sorry, i'm new to development and have worked with sqldatasources only, no idea of object data sources. If you can elaborate further on your method it would be quite helpful. 


Answer5:

As a first thing, read about layered architecture. If you are fimiliar with concepts and ideas behind layered architecture I suugest you to read about design patterns, so you are able to write your code always same way. You may also want to use O/R-mappers to make your life easier because O/R-mappers provide you with data access layer and objects creating runtime.

N-tier architecture helps you many ways. At first - your code is well organized and has less maintaining overhead. Second this is - your code is more reusable. If you have all your data access code behind UI then how are you able to use your business logic behind the other applications like web services or some desktop application? If you are putting your code to layers (Presentation Layer, Business Logic Layer, Data Access Layer) you can write your code so that layers are separated enough to make some reuse. By example - if all your business logic is in BLL and it is separate class librray then you can use same logic and objects in your desktop application, in your web service and in your web application - you provide always only one library to multiple applications. So, if you make some fixes and release you library again then you have made fix in one place and healed, by example, three applications without any additional efforts.


Answer6:

 Thanks DigiMortal for the your view and links which were quite informative. If there is a walk-through which could demonstrate implementation of layered architecture with the help of an example by building a simple application, that would further clarify the concept.

Thanks 


Answer7:
Some links that may help you move on: You can use your own collections and custom objects also with data bound controls. By example, List<Car> that contains objects of type Car can be data source for DataList, GridView and other data bound controls. Instead of data table column names you have to use names of properties in this case.

Related posts

Sign up for PayPal and start accepting credit card payments instantly.


Powered by BlogEngine.NET 1.2.0.0