I have an architecture question. I have DAL project with poco classes (equivalent tables in database), BLL project and UI project. UI project has reference to BLL project and BLL project has reference to DAL project.
I would like to display in UI project data for example from table Product from database. Should I create in BLL project class the same like poco class in DAL project and return it to UI project and display it?
So this is mine poco class in DAL (equivalent table in database):
public class Product
{
public int ID {get; set; }
public string Name {get; set; }
public String Address {get; set; }
}
In BLL I have created business object the same like poco class above:
public class ProductBO
{
public int ID { get; set; }
public string Name { get; set; }
public String Address { get; set; }
}
In BLL I have also method which gets products from DAL and map them to business objects - ProductBO:
public class ProductService
{
public List<ProductBO> GetAllProducts()
{
List<ProductBO> productsBO = new List<ProductBO>();
using (var context = NorthwindFactory.CreateContext())
{
List<Product> products = context.Product.ToList();
foreach (var product in products)
{
productsBO.Add(new ProductBO { ID = product.ID, Address = product.Address, Name = product.Name });
}
}
return productsBO;
}
}
And now in UI project in controller I call service from BLL which returns List and in view I can display data using business object ProductBO.
@model IEnumerable<WebApplication1.BLL.BusinessObjects.ProductBO>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Address)
</th>
</tr>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Address)
</td>
</tr>
}
</table>
Is it correct architecture approach?