Transcript
Page 1: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Th26 - Building High Quality Solutions with Design Patterns & Application Foundations

for SharePoint 2010

Christoffer von Sabsay [email protected]

Page 2: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Agenda • Design Patterns – what, why and when? • Repository Pattern • Service Locator Pattern • Model-View-Presenter Pattern • Application Foundations for SharePoint 2010

Page 3: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

SharePoint vs .NET development • SharePoint is just a .NET application, right? • So are there really any differences between

SharePoint and plain .NET development?

Page 4: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Design Patterns • What is it? • Why should we use it? • When should we use it?

Page 5: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Repository Pattern

Client Business

Logic

Data Source

Repository

Entity – Data Mapping

Business Entity

Business Entity

Persist

Retrieve

Page 6: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Model-View-Presenter Pattern

IView Presenter

Model

View

Page 7: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Service Locator Pattern

Class Service A

Service B

Service Locator

Page 8: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Application Foundations for SP2010

• SharePoint Service Locator • Logger • Configuration Settings Manager

Page 9: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

SharePoint Service Locator using Microsoft.Practices.ServiceLocation; using Microsoft.Practices.SharePoint.Common.ServiceLocation;

IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();

IServiceLocatorConfig typeMappings = serviceLocator.GetInstance<IServiceLocatorConfig>();

typeMappings.RegisterTypeMapping<IService1, Service1>();

IService1 service1 = serviceLocator.GetInstance<IService1>();

Page 10: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Other options for Service Location • Custom implementation • Unity • Spring.NET • StructureMap • Other frameworks

Page 11: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Logger using Microsoft.Practices.ServiceLocation;

using Microsoft.Practices.SharePoint.Common.ServiceLocation;

using Microsoft.Practices.SharePoint.Common.Logging;

using Microsoft.SharePoint.Administration;

IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();

ILogger logger = serviceLocator.GetInstance<ILogger>();

logger.TraceToDeveloper("My message.");

logger.TraceToDeveloper("My message.", TraceSeverity.High);

logger.LogToOperations(msg, EventSeverity.Error);

Page 12: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Configuration Settings using Microsoft.Practices.ServiceLocation; using Microsoft.Practices.SharePoint.Common.Configuration; using Microsoft.Practices.SharePoint.Common.ServiceLocation; IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent(); IConfigManager configManager = serviceLocator.GetInstance<IConfigManager>(); IPropertyBag bag = configManager.GetPropertyBag(ConfigLevel.CurrentSPWebApplication); configManager.SetInPropertyBag("MySetting", DateTime.Now, bag); IHierarchicalConfig config = serviceLocator.GetInstance<IHierarchicalConfig>(); if(config.ContainsKey("MySetting")) lastUpdate = config.GetByKey<DateTime>("MySetting"); configManager.RemoveKeyFromPropertyBag("MySetting", bag);

Page 13: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Summary • Learn about the different design patterns and

when to use them • Use Application Foundations for common

tasks such as configuration and logging

Page 14: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Questions?

Page 15: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Resources Developing Applications for SharePoint 2010 http://msdn.microsoft.com/en-us/library/ff770300.aspx Developing Applications for SharePoint 2007 http://msdn.microsoft.com/en-us/library/ff800762.aspx Application Foundations for SharePoint 2010 http://msdn.microsoft.com/en-us/library/ff798371.aspx

Page 16: Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay

Keep in touch! E-mail: [email protected] Blog: http://christoffervonsabsay.wordpress.com Twitter: sabsay


Top Related