Building a forum application, Part 3
This is the third part in a series of posts where I build a forum application. The other posts can be found here:
In this post I´ll show you the initial structure of the application. I have created a structure and a few base classes for the application, and I tought I´d walk you trought what I have done so far in this post.
I decided to go with 6 projects, 3 test projects and 3 application projects. First I have the web application. Here is all the "web" stuff. Then I have a "core" project. Here I will keep my entity classes, interfaces for services and repositories, the services, helper classes for my model and probably some other stuff aswell that I find logical to keep here. The last project is the "Data" project. Here I will keep my repositories and my NHibernate mappings.
In my web application I will keep my views, my controllers, view helpers and viewmodels. I have created a baseviewmodel that has a PageTitle and a list of breadcrumbs that I can use on any page. My masterpage will have a typed model that is the BaseViewModel. Then I created a BaseController. So far I override the View method and there I set the page title based on the breadcrumbs of my baseviewmodel if the title isn´t allready set. The method now looks like this:
protected override ViewResult View(string viewName, string masterName, object model) { if (model is BaseViewModel) { if (string.IsNullOrEmpty(((BaseViewModel)model).PageTitle)) { var sb = new StringBuilder(); sb.Append(this.Configuration().ApplicationName); if (((BaseViewModel)model).BreadCrumbs != null) foreach (var crumb in ((BaseViewModel)model) .BreadCrumbs) sb.AppendFormat("{0}{1}", this.Configuration() .TitleSeperator, crumb.Name); ((BaseViewModel)model).PageTitle = sb.ToString(); } } return base.View(viewName, masterName, model); }
The "this.Configuration()" is a extension method I created for the BaseController class that gets the default implementation for my interface "IAppConfiguration" from my structuremap repository. IAppConfiguration looks like this:
public interface IAppConfiguration
{
string ApplicationName { get; }
string TitleSeperator { get; }
}
This will, ofcourse, be extended as the application takes form.
The Core project so far contains the model that I presented in my last post. I have allso created a few "helper classes" for my entities. This is basicly a set of extension methods that will help me controll my model while developing the application. To view those more closely you can download the application, I will post a link at the end of this thread. I allso created a BaseService that will handle the most basic stuff that most services need to handle.
My Data project will contain my repositories and the mapping files. I have so far created a BaseRepository that, like the BaseService, handels all the basic stuff that most repositories need. I have allso mapped my entities to the database that I will use.
You can download the source for the application here. I have allso set up a svn repository, so you can download the code from time to time as the project progresses. The url to the server is: https://87.237.213.147:8443/svn/Mattias_Forum. You can log in with username: "User" and no password.

So Mattias insted of making a base View you can use Rob's solution, with data everywhere check out the mix talk about kona :D
Yes, I have considered that a little bit aswell. And I will probably check it out again and try it out. Thanks for the suggestion :)
1 years ago
by
Graham
Why did you decide to have 3 separate application projects, rather than just using namespaces for layering?That is simply a personal preference. I, personaly, feel that I have a better overview of the application if I have it seperated in projects instead of namespaces. Another benefit of having it seperated in different projects is that if you fix a bugg in the data layer, you only need to publish that .dll and not the whole application. But other then that, haveing it seperated using namespaces is equaly "good" as using projects. It comes down to the developers preferences.