This article is a follow-up of, How To Build An Umbraco 7 Document Types In Visual Studio – USiteBuilder Explained . One of the aims of MVC is to be able to separate your presentation logic from your business logic. Being able to define document types with classes provides type-safety, allows us to use IntelliSense in our views and also makes our code testable. Unfortunately, there is a few issue with using uSiteBuilder. For smaller sites, it works well but for larger projects, because uSitebuilder works by scanning all your assemblies on start-up, it can kill performance and make your sites start-up speed to take an age, making development very frustrating. Asides from that, not everyone may want to define document types via a class. In today's post, I am going to cover an alternative way of providing a typed safe architecture in your project, via UmbracoMapper.
public class NewsModel : PublishedContentModel { public NewsModel(IPublishedContent content) : base(content) { } public string MainTitle { get; set; } }
public ActionResult umbHomePage(RenderModel model) { var mapper = new UmbracoMapper(); var viewModel = new NewsModel(model.Content); mapper.Map(CurrentPage, viewModel); return CurrentTemplate(model); }
Software Architect, Programmer and Technologist Jon Jones is founder and CEO of London-based tech firm Digital Prompt. He has been working in the field for nearly a decade, specializing in new technologies and technical solution research in the web business. A passionate blogger by heart , speaker & consultant from England.. always on the hunt for the next challenge