SharePoint 2010 Patterns & Practices

download SharePoint 2010  Patterns & Practices

of 39

  • date post

    22-Feb-2016
  • Category

    Documents

  • view

    37
  • download

    0

Embed Size (px)

description

SharePoint 2010 Patterns & Practices. Serge Luca http://redwood.be Karine Bosch http://karinebosch.wordpress.com. Audience. Audience : SharePoint developers & architects Level : 300. Topics. Introduction to SharePoint Patterns and Practices Guidance (SPG) - PowerPoint PPT Presentation

Transcript of SharePoint 2010 Patterns & Practices

Join & Turn on 2010

SharePoint 2010 Patterns & PracticesSerge Lucahttp://redwood.beKarine Boschhttp://karinebosch.wordpress.com

AudienceAudience : SharePoint developers & architectsLevel : 300

TopicsIntroduction to SharePoint Patterns and Practices Guidance (SPG)Main Patterns covered by the SPGReusable librariesApplication Lifecycle Management for SharePoint 2010Unit testing with Pex & MolesConclusions3TopicsIntroduction to SharePoint Patterns and Practices Guidance (SPG)Patterns covered by the SPGReusable librariesApplication Lifecycle Management for SharePoint 2010Unit testing with Pex & Moles Conclusions4Introduction to SharePoint 2010 Patterns and Practices Guidance (SPG)Team for Microsoft and others (MDSN & CodePlex)Provides:Guidance & documentationPatterns & reference implementationsReusable LibrariesDiscussions listsHands on Labs

(Coding)Challenges when creating enterprise applicationsTestability Can you isolate your classes FlexibilityCan you update or replace code without recompilingConfigurationHow do you manage configuration settings ? Scalability ?Logging and Exception handlingHow do you log ? Consistent across the teamMaintainabilityHow can you maintain code that is always evolvingCan your code run in the Cloud? (Office 365 & the Sandbox)Without Full trust proxyTopicsIntroduction to SharePoint Patterns and Practices Guidance (SPG)Patterns covered by the SPGReusable librariesApplication Lifecycle Management for SharePoint 2010Unit testing with Pex & Moles Conclusions7Patterns covered by the SPGMains patterns illustrated (with reference applications in the SPG)Service Locator patternMVP pattern (Model View Presenter)Repository patternMVVM pattern (Model View View Model)

The Service Locator Pattern9Class AService AService BClass AService AService BLocatorUsesUsesUsesLocatesLocatesSubset of the dependency injection pattern; decouple your code from denpenciesEncourage usage of interfaceCentralize depencies management in the locatorCan return Mock objects instead of real objects

9The Service Locator Pattern

DEMOSee folder Canada_demos\demo1_servicelocatorDemo 1 : without Service locatorDemo 2 : with Service locator; explain that the settings are stored in the farm property bag (SPSite context or if access to SPFarm like a job) or in the Site Collection property bagExplain that it can be used in sandbox mode ->in the cloud

Note http://blogs.msdn.com/b/chriskeyser/archive/2011/01/20/handling-sharepointservicelocator-failures-due-to-caching.aspxThe type mapping is stored in the Cache->if a new type is added, we must delete the cache

Dautres classes utilitaires existent comme SharePointEnvironment.InSandBox10MVP (Model View Presenter) pattern11ViewPresenterModelThe MVP Pattern

DEMOUses the Sandbox reference application \sources\executionModels\sandboxedRun the install file that install the sandbox and populate dataIllustrate the patterns with the help file :1.what the app does : solution overview2.web part design section3.go through the code , show that content types are created by code (EstimateCT feature event receiver)The affregateview pass a pointer of the Model and the View to the presenter = dependency injectionShow that content type are created by code in feature receiver

12The Repository pattern13Client Business LogicYour list repositoryYourSharePointLists + other storagesBusiness EntityBusiness Entity??Choosing a SharePoint Data Access TechnologyLINQFarmSiteList DataExternal ListsData PlatformClient-sideServer-sideStrongly-typedWeakly-typedStrongly-typedWeakly-typedServer OMClient OMREST APIsNew in 2010ImprovedSerge, can you explain what is weakly typed and strongly typed? Not all developers know the difference4/26/2011 7:51 PM 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14The Repository Pattern

DEMOInstall the application in sources\datamodels\datamodels.sharepointlist\setupThe url is http://demo2010a/sites/sharepointlistChoose Manage Machine; test with machien MN0 (dont click on suppliers)

In the Model project, we have the class PartSite (SPMetal generated)In the PartsMgmmt project we have IPartManagementRepository.cs and PartManagementRepository.cs that implements the interfaceUset the UI by going to Search Administration in the Machine model search with MN0Show the ManageMachine web partShow the DTO folder (Data Transfer object): in PartManagementRepository.cs , show the function GetMachineByCategory()Explain role of DTO by showing the MachineDTO et the function GetMachineByCategory() in PartManagementRepository.csShow the spg doc = the data odel + explain many to many implement reverse lookup problem15Linq To SharePoint DSL extensionTo automatically generate a Repository, you can tryLinq To SharePoint DSL Extension from Olivier Carpentier (MCS France)

16MVVM (Model View ViewModel) patternModel : entitiesView Model : bind modelWell adapted to RIA :Optimize benefits of Silverlight & WPF (statefull, 2 ways databinding)Data changed->one or several views should be updated Data stays in memory for longer in RIA->interesting to notify that data changes17ViewView ModelModelUI EventsModel change EventsProperty changedI EventsUpdateReadViewModel dataMVVM

DEMOClientThe View dataContext is set to the ViewModelTest with value sku1

Note that in the project client.SharePoint we have the javacsript code (in \scripts folder)

18TopicsIntroduction to SharePoint Patterns and Practices Guidance (SPG)Patterns covered by the SPGReusable librariesApplication Lifecycle Management for SharePoint 2010Unit testing with Pex & Moles Conclusions19SPG Reusable librariesService LocatorSettings ManagerSharePoint Logger20TopicsIntroduction to SharePoint Patterns and Practices Guidance (SPG)Patterns covered by the SPGReusable librariesApplication Lifecycle Management for SharePoint 2010Unit testing with Pex & Moles Conclusions21Application Lifecycle ManagementCollect and analyze business requirementsEstablish the technical designDevelop the application in iterationsDeploy to test environmentPerform integration tests and performance testDeploy to user acceptance test environmentPerform functional testsDeploy to productionManage bug fixes and change requests

22http://blogs.msdn.com/b/sharepointdeveloperdocs/archive/2010/11/17/application-lifecycle-management-in-microsoft-sharepoint-2010.aspx22Manage Application Lifecycle Management with Team Foundation Server 2010Analyze business requirementsEnter use cases and split into work itemsEnter test scenarios and link to work itemsDevelop the application in iterationsDevelop iteration and link to work itemsBranching/mergingTest the applicationNightly buildsInnovation: Lab ManagementUnit TestsWrite complete test suite or use parameterized tests mock SharePoint objectsIntegration testsPerformance tests Tools for Code Coverage and Code metrics23Activities in TFS:Functional analyst must describe user storiesTechnical analyst must split it up in activitiesTest managers should enter detailed test scenariosDeveloper should write the unit tests based on the test scenarios (= test driven development)

23Application Lifecycle Management for SharePoint 2010Develop Features and SolutionsFeature dependenciesSolution dependenciesFeature versioningFeature.xml changes

FeatureUpgrading event

Unit Testing SharePoint 2010What?Isolate testable pieces of code Determine whether it behaves exactly as you expectTedious to writeLarge percentage of defects are identified during its useRerun after bug fixes can detect newly introduced bugs

Problem with SharePoint: Unit test should run isolatedSharePoint objects like SPSite need connection to SharePointA lot of SharePoint object classes are sealed types with non-public constructors25Developers translate their understanding of the specification into unit tests and/or code. Developers who use test-driven development start by writing unit tests before they start to write code and therefore use the unit tests to drive the design.

A test suite that achieves high code coverage and checks many assertions is a good indicator of code quality.

Unit tests are usually small tests that run fast and give a quick feedback on effects of code changes. Several tools exist to automate the execution of a suite of unit tests on each code change that is committed to the source code repository. One of these tools is Team Foundation Server.

A unit test should test the code in isolation. This means that the developer must hide all environment dependencies such as database and file I/O behind an abstraction layer. The abstraction layer should provide a fake implementation, also referred as mocks. When developing for SharePoint, you should be able to mock your SharePoint environment.

Problem:You cannot execute the functions of the underlying SharePoint Object Model without being connected to a live SharePoint Server.A lot of SharePoint object classes are sealed types with non-public constructors.SPSite for instance cannot be instantiated without a working URL.

25Unit Testing with Visual Studio 2010 Visual Studio 2010 Provide test project template for .NE