more object oriented development with page type builder

24
More object oriented development with Page Type Builder - or how to have a little more fun at work

Upload: joelabrahamsson

Post on 02-Nov-2014

11 views

Category:

Technology


1 download

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

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

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

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

Dear diary, today I……created Page Types

Page 5: More object oriented development with Page Type Builder

Dear diary, today I……added properties

Page 6: More object oriented development with Page Type Builder

Dear diary, today I……added markup to display properties

Page 7: More object oriented development with Page Type Builder

Dear diary, today I……wrote some code

Page 8: More object oriented development with Page Type Builder

Dear diary, today I……did a release

Page 9: More object oriented development with Page Type Builder

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

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

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

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

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

Creating a page typeusing PageTypeBuilder;

namespace MySite.PageTypes{

[PageType] public class Article : TypedPageData { }

}

Page 15: More object oriented development with Page Type Builder

Specifying settings[PageType( Filename = "/Templates/Article.aspx”, DefaultChildSortOrder = FilterSortOrder.Index)]public class Article : TypedPageData{}

Page 16: More object oriented development with Page Type Builder

Adding properties[PageType]public class Article : TypedPageData{

[PageTypeProperty]public virtual string MainBody { get; set; }

}

Page 17: More object oriented development with Page Type Builder

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

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

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

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

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

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

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

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?