View-Post.ascx is the user control responsbile for displaying a post, and it basically just hands the work off to the class, EntryViewContainer. Here is a snippet of EntryViewContainer:
One of the interesting things here that I won’t really go into is the use of a BlogPostQuery object to pass parameters that essentially end up as parameters for stored procedures. This is a nice way to package up parameters as opposed to having several overloads of GetPosts that take varying parameters.
As you can see, EntryViewContainer just grabs the BlogID and PostID along with a few defaults and calls WeblogPosts.GetPosts to go get the post to be displayed. It actually returns a PostSet object, which is basically a thread of posts – the main post and the flow of comments to the post.
Here is where the caching is done as well as where we start to see the data providers coming into action. WeblogDataProvider is an abstract class with not much more than a single method, Instance(), that grabs the concrete data provider class that handles the storage operations for blogs. The concrete class returned is the class that actually carries out the operation to get the post and its comments from data storage. Here is some of the code in WeblogDataProvider:
The main work happens in the CreateDefaultCommonProvider method. It goes out and grabs the configuration information which contains the name of the concrete class that will be handling the data storage and retrieval of blog posts. This information is tucked away in a config file, called communityserver.config, that has the following entry:
There is the concrete class that will actually be handling the blog storage and retrieval: WeblogSqlDataProvider. You can guess that we will need to dynamically create this class during runtime. This is the job of the DataProviders class, which is just a set of helper functions for just that thing:
The CreateInstance method is the work horse that uses reflection to create an instance of the concrete class, WeblogSqlDataProvider, that will eventually get returned to the controller class, WeblogPosts.
As you can see below, WeblogSqlDataProvider is making use of the BlogPostQuery object to pass out the values for the parameters and essentially just calling the stored procedure that returns a few resultsets of data to be passed back as a PostSet.
When you break down the source code like this it becomes pretty clear how all these fundamental OOP techniques come into play . There are a few other goodies in Community Server that are probably worth talking about at a later time, too.