I've been reading Pro ASP.NET 4 and the demo application they use the Entity Framework code first. In my project I've already got the database. In the book they only deal with one table, then create an ITableNameRepository for it, then pass that into the controller's constructor. Is it even right in the first place to make a repository with a model of your entire database? Should I just pass an instance to each controller's constructor of IMyDataModel?
1 Answer
There's a clue in the name of the interface. They called it ITableNameRepository rather than IDatabaseNameRepository
In my application I pass in an IUnitOfWork and that has the various repositories as properties, so the controller's all have a similar constructor signature that doesn't need to change when a controller needs to access a new repository.
The DbContext class is itself a combination of the Unit Of Work and Repository patterns with DbSets acting as repositories and SaveChanges() implementing the unit of work.
The DbContext or IUnitOfWork does mean the controller can access the entire database - but via several repositories not one big one. I use a repository for each table but I have seen many people advocate "aggregate roots"