Reputation: 626
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?
Upvotes: 0
Views: 126
Reputation: 84
use Viewmodel to return result back to controller in business layer and bind view model to View. go through my previous post to learn more or email me if needed detailed information. use unitofwork in business layer not in controller and controller will only get view model returned from business layer either as a object or collection. each view model class would contains set of properties
Upvotes: 1
Reputation: 6011
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.
Upvotes: 2