Th26 - Building High Quality Solutions withDesign Patterns & Application Foundations for SharePoint 2010 Christoffer von Sabsay firstname.lastname@example.org
About Me Christoffer von Sabsay SharePoint Architect Sogeti Sweden MCPD, MCT
Agenda• Design Patterns – what, why and when?• Repository Pattern• Model-View-Presenter Pattern• Service Locator Pattern• Application Foundations for SharePoint 2010
SharePoint vs .NET development• SharePoint is just a .NET application, right?• So are there really any differences between SharePoint and plain .NET development?
Design Patterns• What is it?• Why should we use it?• When should we use it?
Repository Pattern Business Entity Repository Persist Client DataBusiness Source Logic Retrieve Entity – Data Mapping Business Entity
Model-View-Presenter Pattern View IView Presenter Model
Service Locator Pattern Service AClass Service Locator Service B
Benefits after applying these patterns• Repository Pattern – Central point of access to data – can modify storage without too much impact on the rest of the code – Strongly typed access to our data• Model-View-Presenter – Presentation logic separated from UI – Possible to reuse presentation logic for different Uis• Service Locator – Decoupled dependency between presenter and repository – Presenter testable in isolation – Service Locator takes care of creating and managing the lifetime of the service/repository.
Application Foundations for SP2010• SharePoint Service Locator• Logger• Configuration Settings Manager
SharePoint Service Locator• Lightweight Service Locator• Implements the IServiceLocator interface (Microsoft.Practices.ServiceLocation)• Mappings can be stored at the farm or site collection level• Default type mappings – Logging – Configuration Management
Other options for Service Location• Unity• Spring.NET• StructureMap• Other frameworks
Logger• Utility class for logging• Two methods – TraceToDeveloper (ULS) – LogToOperations (Event Log + ULS)• Implements the ILogger interface, easy to replace by custom implementation
Configuration Settings Manager• Utility class for storing and retrieving configuration settings• Settings can be stored in the property bag at different levels – SPFarm, SPWebApplication, SPSite and SPWeb• Also possible to store settings in a SPList
Summary• Learn about the different design patterns and when to use them• Use Application Foundations for common tasks such as configuration and logging
ResourcesDeveloping Applications for SharePoint 2010http://msdn.microsoft.com/en-us/library/ff770300.aspxDeveloping Applications for SharePoint 2007http://msdn.microsoft.com/en-us/library/ff800762.aspxApplication Foundations for SharePoint 2010http://msdn.microsoft.com/en-us/library/ff798371.aspx