This is how I imagine my project's layering:
BLL
Should be independent and contain only pure business logic and properties Sample Domain Model:
public class Role
{
private UnitOfWork uow { get; set; }
public Role()
{
uow = new UnitOfWork();
}
public int RoleId { get; set; }
public string Name { get; set; }
public string ID { get; set; }
public string Description { get; set; }
public int AddRole()
{
//Mapping from Business 'Role' type to Data Model 'Role' type
AutoMapper.Mapper.CreateMap<SoC.BLL.Role, SoC.DAL.Role>();
var model = AutoMapper.Mapper.Map<SoC.DAL.Role>(this);
return uow.Roles.Add(model);
}
}
DAL
Contain generic repository and Unit of work and data model meaning model that will reflect the database. Sample Data Model:
public class Role
{
[Key]
public int RoleId { get; set; }
[Required]
[StringLength(50, ErrorMessage = "Name Cannot Be More Than 50 Characters")]
public string Name { get; set; }
[Required]
[StringLength(6, ErrorMessage = "ID Cannot Be More Than 6 Characters")]
public string ID { get; set; }
[Required]
[StringLength(250, ErrorMessage = "Description Cannot Be More Than 250 Characters")]
public string Description { get; set; }
}
Web
This will be ASP.NET MVC app that will use BLL. (Should or should not be aware of DAL?) Sample Controller Action:
public ActionResult Index()
{
var role = new Role { RoleId = 1, ID = "ADMIN", Name = "Administrator", Description = "Hello World" };
int check = role.AddRole();
return View();
}
So, from app I am communicating with the Domain Model which has a AddRole()
method that will first map using automapper to the equivalent Data Model and then call Add()
of repo method to persist the record.
This way my BLL
is becoming a little dependent on AutoMapper
and DAL
but my DAL
seems independent. I am trying to create just a simple layering for a simple yet well maintained project. Please suggest on its problems and improvements.