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
![Page 1: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/1.jpg)
More object oriented development with Page Type Builder
- or how to have a little more fun at work
![Page 2: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/2.jpg)
Agenda
1. Problems with the standard EPiSever model2. How Page Type Builder solves the problems3. How to use Page Type Builder4. Questions
![Page 3: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/3.jpg)
The EPiServer Model
PageType
PageData Page (.ASPX)
Is, sort of, an instance of
Decides which template to use
Renders content from
![Page 4: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/4.jpg)
Dear diary, today I……created Page Types
![Page 5: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/5.jpg)
Dear diary, today I……added properties
![Page 6: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/6.jpg)
Dear diary, today I……added markup to display properties
![Page 7: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/7.jpg)
Dear diary, today I……wrote some code
![Page 8: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/8.jpg)
Dear diary, today I……did a release
![Page 9: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/9.jpg)
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
![Page 10: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/10.jpg)
What if…
Article
ArticlePage Page<Article> (.ASPX)
Actually is an instance of Decides which template to use
Renders content from,knowing the type
![Page 11: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/11.jpg)
Page Type Builder
• An open source project• Creates and updates page types based on classes• Ensures that DataFactory returns instances of your
classes
![Page 12: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/12.jpg)
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
![Page 13: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/13.jpg)
Getting started• Download from
pagetypebuilder.codeplex.com• Reference PageTypeBuilder.dll• Copy Castle.Core.dll and
Castle.DynamicProxy2.dll to your bin folder
![Page 14: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/14.jpg)
Creating a page typeusing PageTypeBuilder;
namespace MySite.PageTypes{
[PageType] public class Article : TypedPageData { }
}
![Page 15: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/15.jpg)
Specifying settings[PageType( Filename = "/Templates/Article.aspx”, DefaultChildSortOrder = FilterSortOrder.Index)]public class Article : TypedPageData{}
![Page 16: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/16.jpg)
Adding properties[PageType]public class Article : TypedPageData{
[PageTypeProperty]public virtual string MainBody { get; set; }
}
![Page 17: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/17.jpg)
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; }}
![Page 18: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/18.jpg)
Creating a templateusing PageTypeBuilder.UI;
namespace MySite.Templates{
public partial class Article : TemplatePage<PageTypes.Article> { }
}
![Page 19: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/19.jpg)
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>
![Page 20: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/20.jpg)
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;}
}
![Page 21: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/21.jpg)
Adding methods to page types[PageType]public class Article : TypedPageData{ public IEnumerable<Comment> GetComments() { return DataFactory.Instance.GetChildren(PageLink) .OfType<Comment>(); }}
![Page 22: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/22.jpg)
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>(); }}
![Page 23: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/23.jpg)
Where to learn more
pagetypebuilder.codeplex.com
• Links to tutorials• Links to 40+ blog posts
![Page 24: More object oriented development with Page Type Builder](https://reader036.vdocuments.net/reader036/viewer/2022081412/54558a84af7959d2368b6578/html5/thumbnails/24.jpg)
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?