I am designing my first Layered Application which consists of a Data, Business, and a Presentation layer.
My business components (e.g, Business.Components.UserComponent) currently has the following method:
public void Create(User entity)
{
using (DataContext ctx = new DataContext())
{
ctx.Users.AddObject(entity);
ctx.SaveChanges();
}
}
I like this design. However, I've encountered some examples online that would recommend the following implementation:
public void Create(User entity)
{
// Instanciate the User Data Access Component
UserDAC dac = new UserDAC();
dac.InsertUser(entity);
}
This would result in creating a Data Access Component for all Entities, each containing the basic methods (Create, Edit, Delete...etc).
This seems like double work since I would have to create the Data Access Components with the basic methods as well as the Business Components that just simply calls the methods in the Data Access Component.
What would be considered best practice for properly implementing the basic CRUD functionalities in a Layered Application? Should they be 'coded' in the Business Component or in a Data Access Component?