Search code examples
architectureasp.net-mvc-5service-layerbusiness-logic-layer

Asp.net mvc How is the better way to build Business Logic Layer?


Hello I have a project that is communicating directly with the DAL layer.

In DAL layer I'm using two patterns: Repository and Unit Of Work.

In my controller I create the instance of Unit Of Work and use as follows:

protected readonly IUnitOfWork unitOfWork;    

public MyController(IUnitOfWork unitOfWork)
{
    this.unitOfWork = unitOfWork;
}

Now I'm trying implement the business layer, but I'm confused on how to do.

In the business layer I will create a class of service for each repository. Each class of service must be able to communicate with one or more repositories. The UI project should communicate only with Business project, right?


Solution

  • If you want a somewhat good architecture, I strongly advise you look at (and download) nopCommerce.

    The idea is that you open the solution and look at how they do things and take whatever you think is relevant to your own project.

    You’ll notice that a Controller talks to not one, but many services which in turn, those services talk to (and use) the repository and Unit Of Work.

    This approach makes your Controllers less messy since you’re delegating work to the other layers which in turn makes your code more readable and maintainable.

    HTH.