More object oriented development with Page Type Builder

3,839 views

Published on

An introduction to Page Type Builder, a plugin that introduces a more object oriented and easier way to work with EPiServer CMS.

Published in: Technology, Business
  • Be the first to comment

  • Be the first to like this

More object oriented development with Page Type Builder

  1. 1. More object oriented development with Page Type Builder<br />-or how to have a little more fun at work<br />
  2. 2. Agenda<br />Problems with the standard EPiSevermodel<br />How Page TypeBuildersolves the problems<br />How to use Page TypeBuilder<br />Questions<br />
  3. 3. The EPiServer Model<br />PageType<br />Is, sort of, an <br />instance of<br />Decideswhich<br />template to use<br />PageData<br />Page (.ASPX)<br />Renderscontent from<br />
  4. 4. Deardiary, today I…<br />…created Page Types<br />
  5. 5. Deardiary, today I…<br />…addedproperties<br />
  6. 6. Deardiary, today I…<br />…addedmarkup to display properties<br />
  7. 7. Deardiary, today I…<br />…wrotesomecode<br />
  8. 8. Deardiary, today I…<br />…did a release<br />
  9. 9. A few problems<br />Wespend a lot of time not writingcode<br />Wedefine ”templates” for objects in a webbased UI<br />There’s no inheritancebetween page types<br />Synchronizing different environments is a pain<br />ObjectOrientation?<br />Weuse a lot of ”magic strings”<br />Weplacelogic in the presentation layer that doesn’tnecessarilybelongthere<br />WedistinguishPageDataobjects by the ID of their Page Type<br />
  10. 10. Whatif…<br />Article<br />Decideswhich<br />template to use<br />Actually is an instance of<br />ArticlePage<br />Page<Article> (.ASPX)<br />Renderscontent from,<br />knowing the type<br />
  11. 11. Page TypeBuilder<br />An opensourceproject<br />Creates and updates page typesbased on classes<br />Ensures that DataFactoryreturnsinstances of your classes<br />
  12. 12. By using Page TypeBuilderwe get<br />Less switchingbetween Visual Studio and Admin<br />Inheritancebetween page types<br />Stronglytyped access to properties<br />The ability to placelogic in pages<br />Polymorphism<br />Faster and easier releases<br />Bettertestability<br />
  13. 13. Getting started<br />Download from pagetypebuilder.codeplex.com<br />ReferencePageTypeBuilder.dll<br />CopyCastle.Core.dll and Castle.DynamicProxy2.dll to your bin folder<br />
  14. 14. Creating a page type<br />usingPageTypeBuilder;<br />namespaceMySite.PageTypes<br />{<br />[PageType]<br />public classArticle : TypedPageData<br /> {<br /> }<br />}<br />
  15. 15. Specifying settings<br />[PageType(<br />Filename ="/Templates/Article.aspx”,<br />DefaultChildSortOrder =FilterSortOrder.Index)]<br />public classArticle : TypedPageData<br />{<br />}<br />
  16. 16. Addingproperties<br />[PageType]<br />public classArticle : TypedPageData<br />{<br /> [PageTypeProperty]<br />public virtual stringMainBody { get; set; }<br />}<br />
  17. 17. Specifyingproperty settings<br />[PageType]<br />public classArticle : TypedPageData<br />{<br /> [PageTypeProperty(<br />EditCaption ="Main body",<br />HelpText = "Will be shown in the main content area of the page",<br />Type = typeof(PropertyXhtmlString))]<br />public virtual stringMainBody { get; set; }<br />}<br />
  18. 18. Creating a template<br />usingPageTypeBuilder.UI;<br />namespaceMySite.Templates<br />{<br />public partialclassArticle : TemplatePage<PageTypes.Article><br /> {<br /> }<br />}<br />
  19. 19. Creating a template<br /><%@ PageLanguage="C#"CodeBehind="Article.aspx.cs"<br />Inherits="MySite.Templates.Article"<br />MasterPageFile="~/Templates/MasterPages/MasterPage.master"%><br /><asp:ContentContentPlaceHolderID="MainBodyRegion"runat="server"><br /><%= CurrentPage.MainBody%><br /></asp:Content><br />
  20. 20. Addlogic to properties<br />[PageTypeProperty(Type = typeof(PropertyString))]<br />public string Heading<br />{<br /> get<br />{<br /> string heading=<br />this.GetPropertyValue(page => page.Heading);<br /> if (!string.IsNullOrEmpty(heading))<br /> return heading;<br /> return PageName;<br />}<br />}<br />
  21. 21. Addingmethods to page types<br />[PageType]<br />public classArticle : TypedPageData<br />{<br /> publicIEnumerable<Comment> GetComments()<br /> {<br />return<br />DataFactory.Instance.GetChildren(PageLink)<br /> .OfType<Comment>();<br /> }<br />}<br />
  22. 22. DependencyInjection<br />[PageType]<br />public classArticle : TypedPageData<br />{<br />privateIPageSourcedataFactory;<br />public Article(IPageSourcedataFactory)<br />{<br />this.dataFactory = dataFactory;<br />}<br /> publicIEnumerable<Comment> GetComments()<br /> {<br />returndataFactory.GetChildren(PageLink)<br /> .OfType<Comment>();<br /> }<br />}<br />
  23. 23. Where to learnmore<br />pagetypebuilder.codeplex.com<br /><ul><li>Links to tutorials
  24. 24. Links to 40+ blog posts</li></li></ul><li>Thank you!<br />Questions?<br />http://joelabrahamsson.com<br />@joelabrahamsson<br />joel.abrahamsson@valtech.se<br />Photographs from <br />http://draken413o.deviantart.com/art/To-the-rescue-121441303 <br />and <br />http://theinfluentials.wordpress.com/category/consumer-behaviour/<br />

×