More work for the data provider developers!
Generally speaking I feel there has to be a very good reason for making an area more complex for people who want to extend the projects you create. So far it has been really simple creating a new data provider for MVC Forum. All you have to do is implement a generic repository class, and a UnitOfWork class. That was all that was required by MVC Forum.
With the changes I'm working on right now, which will be in the 3rd alpha release of MVC Forum, it is going to take some more work! A lot of the logic/code that has been in the controllers until now will be moved to specific repositories. So instead of just implementing a class with the IRepository<TEntity> interface, you're now going to have to implement a class with the ITopicRepository interface too (and a bunch of other classes and interfaces).
What's the good reason, you're asking?
Performance is the answer! With Entity Framework and LINQ you can do a lot of things that will actually "stay in the database", which is what we look for in a good data provider. What we're not interested in is that thousands of posts will be pulled out of the database and instantiated as objects, just to get the 10 or 20 posts we need to actually show in the UI. So the reason for making it more complex to make a data provider for MVC Forum, is that we want to make it possible for the data provider developers to make it perform the best. This can only be done by allowing data provider developers to optimizing parts of the code, in the data provider.
Time for an example, taken from the ForumController:
// Before: IList<Topic> topics = topicRepo .ReadMany(new TopicSpecifications.Stickies(forum)) .OrderByDescending(t => t.LastPosted) .ThenByDescending(t => t.Posted) .Concat( topicRepo .ReadMany(new TopicSpecifications.Regulars(forum)) .OrderByDescending(t => t.LastPosted) .ThenByDescending(t => t.Posted) ) .Skip<Topic>((page - 1) * (this.config.TopicsPerPage - announcementCount)) .Take(config.TopicsPerPage - announcementCount).ToList(); // After: IList<Topic> tops = this.topicRepo.ReadStickiesAndRegulars(forum, isModerator, page, announcements.Count);
Entity Framework will not actually take data from the database and instantiate objects based on the data before we reach the ToList() call, but if I were to implement a NHibernate data provider, it would return all topics and then start working on them (the way is was written before). Now, with the data provider specific topic repository, the code can be optimized to do as much work as possible in the database, before starting to instantiate the objects.
Categories: MVC Forum - EF41 - Alpha 3 - NHibernate
Posted by Steen F. Tøttrup on 26 October 2011 09:59. There are 1 comments.
Comments
Write new comment

29 October 2011 07:07 by Steen F. Tøttrup:
The very first comment, just a small test! It works?