locked
Application Organization + Validation RRS feed

  • Question

  • User-626088549 posted

    This is kind of a two-part thread. The first thing I want to talk about, or more accurately, get input about, is how you organize your apps. I'm currently working on an app that, as of now, consists of two projects: MyApp.Core and MyApp.UI. MyApp.UI is a MVC 3 project and has reference to MyApp.Core.

    MyApp.Core has folders "Models" for my Domain model and "Services" for services. What else might you all put in this location? Also, I see a lot of sample apps that have a third project (or sometimes just a folder in the "Core" project) that is called "Infrastructure". What exactly is defined as "Infrastructure"?

    Secondly, I'm interested in some samples of validation. IMO, validation should occur in at least two different places: at the Domain level for business-like validation and at the UI level for input validation (e.g. verify an input field contains a valid date, etc.). How do you go about implementing such validation at these two different levels and any other levels where you may do some validation. 

    Looking forward to your insights on this :)

    Wednesday, April 20, 2011 10:00 AM

Answers

  • User-952121411 posted

    What exactly is defined as "Infrastructure"?

    Your Infrastructure layer is a single project that could contain Utility type functionality, configuration wrapping, etc. that should be available to all layers. If I were drawing a diagram, the traditional layers (depending on architecture) would lay horizontally on top of each other. The Infrastructure layer would run vertically to the right of all layers, meaning it is accessible and used in all layers.

    Secondly, I'm interested in some samples of validation. IMO, validation should occur in at least two different places: at the Domain level for business-like validation and at the UI level for input validation (e.g. verify an input field contains a valid date, etc.). How do you go about implementing such validation at these two different levels and any other levels where you may do some validation. 

    Sounds good to me! Doing validation at both layers is being thorough and correct. Many times devs will only attempt to validate logic at the UI layer leaving them prone to attacks, mistakes, improperly formatted data being persisted, etc.

    At the UI layer you can use tools like ASP.NET Validator Controls, AJAX Toolkit controls, jQuery, JavaScript, or server side checks behind the form. At the lower levels you will probably cleanse or check the data again using type checks, applying business rules for validity, adding as SQLParameters if using stored procedures to help prevent injection attacks, etc.

    A book you might enjoy that touches upon these topics amoung many, many others about architecture and project organization is the one below:

    Professional ASP.NET Design Patterns:

    http://www.amazon.com/Professional-ASP-NET-Design-Patterns-Millett/dp/0470292784

    Hope this helps!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 20, 2011 3:34 PM

All replies

  • User-952121411 posted

    What exactly is defined as "Infrastructure"?

    Your Infrastructure layer is a single project that could contain Utility type functionality, configuration wrapping, etc. that should be available to all layers. If I were drawing a diagram, the traditional layers (depending on architecture) would lay horizontally on top of each other. The Infrastructure layer would run vertically to the right of all layers, meaning it is accessible and used in all layers.

    Secondly, I'm interested in some samples of validation. IMO, validation should occur in at least two different places: at the Domain level for business-like validation and at the UI level for input validation (e.g. verify an input field contains a valid date, etc.). How do you go about implementing such validation at these two different levels and any other levels where you may do some validation. 

    Sounds good to me! Doing validation at both layers is being thorough and correct. Many times devs will only attempt to validate logic at the UI layer leaving them prone to attacks, mistakes, improperly formatted data being persisted, etc.

    At the UI layer you can use tools like ASP.NET Validator Controls, AJAX Toolkit controls, jQuery, JavaScript, or server side checks behind the form. At the lower levels you will probably cleanse or check the data again using type checks, applying business rules for validity, adding as SQLParameters if using stored procedures to help prevent injection attacks, etc.

    A book you might enjoy that touches upon these topics amoung many, many others about architecture and project organization is the one below:

    Professional ASP.NET Design Patterns:

    http://www.amazon.com/Professional-ASP-NET-Design-Patterns-Millett/dp/0470292784

    Hope this helps!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 20, 2011 3:34 PM
  • User-626088549 posted

    Thanks for the reply. Sorry it took so long for me to get back to this - I've been busy working on other things. So here's a related question: Would you use the DataAnnotations on the domain objects as well as on ViewModels? 

     

    Cheers

    Thursday, April 28, 2011 9:25 AM