This is the first time I'm doing a web project using MVC and I'm trying to make it based on three layers : MVC, DAL (Data Access Layer) and BLL (Business Logic Layer).
I'm also trying to use repositories and I'm doing it code-first.
Anyway I've searched a lot on the web but yet if you've got a good reference for me I'll be glad to see it .
My current project looks like this:
And here are my questions:
Where are the Product and User classes that represent tables supposed to be? It seems that I need to use them in the BLL and I don't really need them in the DAL but for the
PASContext
.Where do I initiate the
PASContext
? In all of the examples I've seen on the internet no one made a constructor in the repository that takes 0 argument, which means that the context is not created within the repository (and I've read some reasons why like so all repositories will use one context).
If I'm trying to initiate the PASContext
in the ProductBLL
the compiler says it doesn't recognize it and I'm missing a reference (although I've added the needed reference and the name PASContext
is marked in a blue like vs did recognize it)
PASContext
is the class that is inherited from DbContext
.
Here is some code to demonstrate:
public class ProductsBLL
{
private EFRepository<Product> productsRepository;
private List<Product> products;
public ProductsBLL()
{
PASContext context = new PASContext();
productsRepository = new EFRepository<Product>(context);
//LoadData();
}
- About the View models, if I want, for example, to present a list of products for the client, do I need to create a
ProductViewModel
, get the data fromProductsBLL
which has a list of Product and convert it to a list ofProductViewModel
and then send it to the controller?
In addition, in the ProductController
, do I only initiate ProductsBLL
? I don't initiate any repository or context, right?
If someone could show me some project that uses repository, three-tier architecture and takes data from the database, transfers it to the BLL and from there to the MVC layer and using a ViewModel
show it to the client it will be great.