One of SharePoint’s greatest strengths is its flexibility and the possibility to quickly build powerful solutions with the web UI and SharePoint Designer. However, when building business critical enterprise applications, it’s important to make your solution maintainable by using the same standard design patterns and best practices that applies to ordinary .NET development.
In this session, we will talk about several different design patterns such as repository, service location and model-view-presenter that will help you build SharePoint solutions that are flexible, testable and maintainable. We will discuss the different considerations you have to make when deciding to use these patterns. We will also go through the Application Foundations library for SharePoint 2010 from Microsoft, which provides support for managing configuration, service location and logging.
Building High Quality Solutions with Design Patterns & Application Foundations for SharePoint 2010 presented by Christoffer von Sabsay
1. Th26 - Building High Quality Solutions with
Design Patterns & Application Foundations
for SharePoint 2010
Christoffer von Sabsay
christoffer.von.sabsay@sogeti.se
2. Agenda
•
•
•
•
•
Design Patterns – what, why and when?
Repository Pattern
Service Locator Pattern
Model-View-Presenter Pattern
Application Foundations for SharePoint 2010
3. SharePoint vs .NET development
• SharePoint is just a .NET application, right?
• So are there really any differences between
SharePoint and plain .NET development?
9. 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>();
10. Other options for Service Location
•
•
•
•
•
Custom implementation
Unity
Spring.NET
StructureMap
Other frameworks
11. 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);
12. 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);
13. Summary
• Learn about the different design patterns and
when to use them
• Use Application Foundations for common
tasks such as configuration and logging