Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 621397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:52:11+00:00 2026-05-13T18:52:11+00:00

I am attempting to create the the business and data layers for my big

  • 0

I am attempting to create the the business and data layers for my big ASP.NET MVC application. As this is the first time for me attempting a project of this scale I am reading some books and trying to take good care at separating things out properly. Usually my applications mix the business logic and data access layers, and multiple business entities are intertwined in the single class (which has confused me a few times when I was trying to figure out where to add things).

Most of what I have been reading is to separate out the business and data layers. This seems all fine and dandy, but I am having trouble visualizing exactly how to do this in some scenarios. For example, let’s say I am creating a system that allows admins to add a new product to the system:

public class Product
{ 
   public int Id { get; private set; }
   public string Name { get; set; }
   public decimal Price { get; set; }
}

Then I separate out the data access by creating a repository

public class ProductRepository
{
   public bool Add(Product product);
}

Let’s say I want to require a product’s name to have at least 4 characters. I can’t see how to do this cleanly.

One idea I had was to expand the Name’s set property and only set it if it’s 4 characters long. However, there is no way for a method that is creating the product to know the name didn’t get set except that Product.Name != whatever they passed in.

Another idea I had is to put it in the Add() method in the repository, but then I have my business logic right there with the data logic, which also means if the Add call fails I don’t know if it failed for the business logic or because the DAL failed (and it also means I can’t test it using mock frameworks).

The only thing I can think of is to put my DAL stuff in a 3rd layer that gets called from the Add() method in the repository, but I don’t see this in any of the domain modelling examples in my book or on the web (that I’ve seen at least). It also adds to the complexity of the domain models when I am not sure it is needed.

Another example is wanting to make sure that a Name is only used by one product. Would this go in the Product class, ProductRepository Add() method, or where?

As a side note, I plan to use NHibernate as my ORM however, to accomplish what I want it (theoretically) shouldn’t matter what ORM I am using since TDD should be able to isolate it all.

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:52:11+00:00Added an answer on May 13, 2026 at 6:52 pm

    I usually approach this by using a layered architecture. How to do this? You basically have the following (ideally) VS projects:

    • Presentation layer (where the UI stuff resides)
    • Business layer (where the actual business logic resides)
    • Data access layer (where you communicate with your underlying DBMS)

    For decoupling all of them I use so-called interface layers s.t. in the end I have

    • Presentation layer (where the UI
      stuff resides)
    • IBusiness layer (containing the interfaces for the
      business layer)
    • Business layer (where
      the actual business logic resides)
    • IDataAccess layer (containing the
      interfaces for the DAO layer)
    • Data access layer (where you communicate
      with your underlying DBMS)

    This is extremely handy and creates a nicely decoupled architecture. Basically your presentation layer just accesses the interfaces and not the implementations itself. For creating the according instances you should use a Factory or preferably some dependency injection library (Unity is good for .Net apps or alternatively Spring.Net).

    How does this impact on your business logic / testability of your app?
    It is probably too long to write everything in detail, but if you’re concerned about having a well testable design you should absolutely consider dependency injection libraries.

    Using NHibernate,…whatever ORM
    Having a DAO layer completely separated through the interfaces from the other layers you can use whatever technology behind for accessing your underlying DB. You could directly issue SQL queries or use NHibernate, as you wish. The nice thing is that it is totally independent from the rest of your app. You could event start today by writing SQLs manually and tomorrow exchange your DAO dll with one that uses NHibernate without a single change in your BL or presentation layer.
    Moreover testing your BL logic is simple. You may have a class like:

    public class ProductsBl : IProductsBL
    {
    
       //this gets injected by some framework
       public IProductsDao ProductsDao { get; set; }
    
       public void SaveProduct(Product product)
       {
          //do validation against the product object and react appropriately
          ...
    
          //persist it down if valid
          ProductsDao.PersistProduct(product);
       }
    
       ...
    }
    

    Now you can easily test the validation logic in your SaveProduct(...) method by mocking out the ProductDao in your test case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to create a web app that works with business data models, pretty
I'm attempting to create a custom calendar control that inherits from ASP.Net's built in
I am attempting to create a small application to collect data received from an
I attempting to create custom tabs using this . But when I try to
I'm attempting to create a small application in which I can make a poul
I'm attempting to create a Windows application that will allow the controls on earbuds/headphones
I'm currently attempting to create a tabbed interface in a web application, and based
I am attempting to create new membership users in an Ektron CMS400.NET-based website by
I'm attempting to create (in XCode) a Tabbed Application, which houses in one of
When attempting to create an Azure project in Visual Studio 2010 I get a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.