Video: Creating an N-Layer ASP.NET Application (Updated)

In this video tutorial I walk through the fundamentals of creating an N-Layer ASP.NET application.  What's "N-Layer" you ask?  N-Layer can be interpreted many different ways, but I generally use the term to mean separating presentation, business and data code into individual code layers.  Doing this allows code to be re-used throughout an application and prevents unnecessary clutter in ASP.NET code-behind classes.  This video covers creating presentation, business and data layers and also covers another layer I normally add to projects that I refer to as "Model".  The model layer contains data entity classes that are used to pass data between the different layers. 

If you're currently embedding all of your code directly in ASP.NET pages, this video will help get you started on the road to recovery.  I'm kidding of course, but if you want to build more re-useable and maintainable applications you'll want to segregate your code into different layers at a minimum.  Other types of architectures can certainly be applied as well.

View the Video

 

My article in asp.netPRO Magazine that compliments the video can be viewed here.

 
Thanks to Orcsweb for hosting my website (http://www.xmlforasp.net) and for giving me space to host videos!  If you're looking for a host I highly recommend them.  You won't find better service anywhere.

comments powered by Disqus

9 Comments

  • Great video! 30 minutes covers everything. We need more videos like this, not just the Hello World video's using drag 'n drop. I have a couple of questions:

    1. Why not store the schema in the Model folder?
    2. Why bind the data tier to a webapp by using webconfigurationmanager and httpcontext?
    3. Why bother with an array, wouldn't it be better to just pass the generic list?

    Could you do a video where you have a totally different model from the database?

    Thanks again! Adding blog to favorites....

  • Glad you enjoyed the video. As far as your questions, if I stick the schema in the app_code folder it'll automatically generate a strongly-typed DataSet for me. While that's fine, it's not what I wanted to show here. I prefer a pure streaming approach where possible with small objects being passed between layers to keep overhead down to a minimum.

    As far as question 2, there are certainly different ways to handle that (such as the more generic ConfigurationManager...I probably should've used that actually) but, the goal was to keep it fairly simple. Trace listeners or writing to the event log could certainly be used instead of directly calling Trace.Warn(). Since I knew the video would already be fairly long I went with the quick approach. :-) I typically am working on Web apps or Web Service apps so HttpContext is always available...but to make it "truly" re-useable across maybe desktop apps then I'd certainly choose a different approach for logging errors. Since this was specifically for ASP.NET I went the route shown in the video though.

    For the List, that would be fine to return of course, but I prefer to keep the overhead of objects passed between the layers as minimal as possible. Just a personal choice. If I knew the collection would have to be increased potentially then I'd pass the List.

  • Nice..concise and to the point. Helpful for newbies.

  • Why the video can't be downloaded?

  • You can download it. Once on the video page, right-click on the view in media player link and select Save Target As. That will let you download it to your machine.

  • Thanks for a great video.
    I'm starting off a small project with this methods right away.

    A little question though:
    When creating my .cs-file from the .xsd the .cs-file wants to be set as a partial class below the .xsd (unless I set the output directory). As far as i can see I have used the same parameters as you do in the video (apart from setting a fully qualified namespace which you pointed out). Is there any special setup or any occasions where this is supposed to happen?

  • Hi Dan,
    This is the best Video I have ever seen in his category. Please post more video in some advance level.
    Thanks,
    Mazhar

  • Great video. One question. How would you bind the list of customers from the aspx codebehind to a gridview?

  • I would normally just use the ObjectDataSource to bind the list of customers returned from the business layer. But, you could always write code to assign them to the GridView's DataSource property and then call DataBind().

Comments have been disabled for this content.