more object oriented development with page type builder
DESCRIPTION
An introduction to Page Type Builder, a plugin that introduces a more object oriented and easier way to work with EPiServer CMS.TRANSCRIPT
More object oriented development with Page Type Builder
- or how to have a little more fun at work
Agenda
1. Problems with the standard EPiSever model2. How Page Type Builder solves the problems3. How to use Page Type Builder4. Questions
The EPiServer Model
PageType
PageData Page (.ASPX)
Is, sort of, an instance of
Decides which template to use
Renders content from
Dear diary, today I……created Page Types
Dear diary, today I……added properties
Dear diary, today I……added markup to display properties
Dear diary, today I……wrote some code
Dear diary, today I……did a release
A few problems• We spend a lot of time not writing code
– We define ”templates” for objects in a web based UI– There’s no inheritance between page types– Synchronizing different environments is a pain
• Object Orientation?– We use a lot of ”magic strings”– We place logic in the presentation layer that doesn’t
necessarily belong there
• We distinguish PageData objects by the ID of their Page Type
What if…
Article
ArticlePage Page<Article> (.ASPX)
Actually is an instance of Decides which template to use
Renders content from,knowing the type
Page Type Builder
• An open source project• Creates and updates page types based on classes• Ensures that DataFactory returns instances of your
classes
By using Page Type Builder we get
• Less switching between Visual Studio and Admin• Inheritance between page types• Strongly typed access to properties• The ability to place logic in pages• Polymorphism• Faster and easier releases• Better testability
Getting started• Download from
pagetypebuilder.codeplex.com• Reference PageTypeBuilder.dll• Copy Castle.Core.dll and
Castle.DynamicProxy2.dll to your bin folder
Creating a page typeusing PageTypeBuilder;
namespace MySite.PageTypes{
[PageType] public class Article : TypedPageData { }
}
Specifying settings[PageType( Filename = "/Templates/Article.aspx”, DefaultChildSortOrder = FilterSortOrder.Index)]public class Article : TypedPageData{}
Adding properties[PageType]public class Article : TypedPageData{
[PageTypeProperty]public virtual string MainBody { get; set; }
}
Specifying property settings[PageType]public class Article : TypedPageData{
[PageTypeProperty( EditCaption = "Main body", HelpText = "Will be shown in the main content area of the page", Type = typeof(PropertyXhtmlString))]
public virtual string MainBody { get; set; }}
Creating a templateusing PageTypeBuilder.UI;
namespace MySite.Templates{
public partial class Article : TemplatePage<PageTypes.Article> { }
}
Creating a template<%@ Page Language="C#" CodeBehind="Article.aspx.cs" Inherits="MySite.Templates.Article"MasterPageFile="~/Templates/MasterPages/MasterPage.master"%>
<asp:Content ContentPlaceHolderID="MainBodyRegion" runat="server">
<%= CurrentPage.MainBody %></asp:Content>
Add logic to properties[PageTypeProperty(Type = typeof(PropertyString))]public string Heading{
get{ string heading = this.GetPropertyValue(page => page.Heading); if (!string.IsNullOrEmpty(heading)) return heading;
return PageName;}
}
Adding methods to page types[PageType]public class Article : TypedPageData{ public IEnumerable<Comment> GetComments() { return DataFactory.Instance.GetChildren(PageLink) .OfType<Comment>(); }}
Dependency Injection[PageType]public class Article : TypedPageData{ private IPageSource dataFactory; public Article(IPageSource dataFactory) { this.dataFactory = dataFactory; } public IEnumerable<Comment> GetComments() { return dataFactory.GetChildren(PageLink) .OfType<Comment>(); }}
Where to learn more
pagetypebuilder.codeplex.com
• Links to tutorials• Links to 40+ blog posts
Thank you!
http://joelabrahamsson.com@joelabrahamsson
[email protected] from http://draken413o.deviantart.com/art/To-the-rescue-121441303 and http://theinfluentials.wordpress.com/category/consumer-behaviour/
Questions?