Introduction
As I have a strong interest in software architecture I will be giving an overview of the architecture I have used to create my multisite content management system, which will be open to your suggestions for improvement. I have aimed to create a loosely coupled – highly coherent architecture to keep the application maintainable and as extensible as possible as I plan to add new features as an when they are needed.
Technologies used
- Unity application block for dependency injection
- Asp.net MVC
- Entity Framework
- JQuery
Architecture
The architecture consist of a Repository layer a Services layer and Asp.net MVC for the presentation.
The repository layer is responsible for getting objects in and out of the datastore which are to be used by the service layer. The service layer is responsible for applying the business rules and providing the presentation with required services.
I have tried to show the basic overview below. I will go in to more detail a bit later on, but basically the services for example have a reference to the IGalleryRepository and Unity takes care of creating a new instance of the EntityFrameworkGalleryRepository.
To keep the Entities generated by the Entity Framework out of the rest of my application and keep the dependency on the Entity Framework contained to the EntityFrameworkRepository that implements the repository interface, the entities are mapped to POCOs. This will enable me to switch to Linq-Sql or some other data storage strategy will a lot less hassle.
public TextContentRepository.Concrete.TextContent GetTextContent(int textContentId, Guid applicationId)
{
using (entities = GetContext())
{
JJCore.TextContent textContent = entities.TextContent
.Include("ApplicationPage")
.FirstOrDefault(
t => t.TextContentId == textContentId
&&
t.ApplicationPage.Application.Id ==
applicationId);
JJRepositories.TextContentRepository.Concrete.TextContent toReturn =
new JJRepositories.TextContentRepository.Concrete.TextContent(textContent);
return toReturn;
}
}
Above is an example of using the entity framework while keeping the rest of the application isolated from it.
I have created a POCO with a constructor that takes the entity as an argument but I will be improving this by creating a Mapper class, by using
AutoMapper or by switching to Entity Framework 4 to make use of
POCOs.
I would also like to remove the magic string for the includes in the near future too.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Application application)
{
application.Validate(ModelState);
if (!ModelState.IsValid)
return View(application);
applicationService.SaveApplication(application);
return RedirectTo
Action("Index");
}
The above is an Action on the SitesController. It has one specific responsibility.
Pass the application to be saved if it is valid.
I have not gone in to much detail on the MVC part of the implementation, I'll save that for another post. I have ensured that I am always programming to interfaces to allow for easier unit tests (another post) and dependency injection.
I hope I managed to describe the architecture and I welcome you comments and suggestions for improvement.