In the following code, DbContext instantiates repositories in derived class. I believe it does this somehow by reflection in its constructor. These are my questions :
- Why and for which purpose it does it?
- Is instantiating properties in self or derived classes a best practice?
- If it is a best practice which design pattern is it related to and what is the name of this behavior?
This is the only code in my project, I just add entityframework reference to a console application project :
class Program
{
static void Main(string[] args)
{
var context = new DataContext();
if(context.Products != null)
Console.WriteLine("why repositories are not null?!");
}
}
public class Product
{
}
public class DataContext : DbContext
{
public IDbSet<Product> Products { get; set; }
}
Aucun commentaire:
Enregistrer un commentaire