选择 SharePoint 加载项设计选项时的三种考虑方式Three ways to think about design options for SharePoint Add-ins

先决条件:应先熟悉 SharePoint 加载项一文。Prerequisite: You should first be familiar with the article SharePoint Add-ins.

本文介绍了选择 SharePoint 加载项体系结构选项时的三种考虑方式。This article looks at the architectural choices for SharePoint Add-ins in three different ways. 首先,了解最重要类别的设计选项有哪些;其次,从应用层角度出发审视加载项体系结构;再者,了解在选择设计选项时需要考虑的一系列因素。First, you learn about the most important categories of design choices; second, you view add-in architecture in terms of application tiers; and, third, you see a set of factors you need to consider when making your design choices.

要做出的第一个决定是,SharePoint 扩展应该是 SharePoint 加载项,还是经典 SharePoint 场解决方案或沙盒解决方案。The first decision to make is whether your SharePoint extension should be a SharePoint Add-in or a classic SharePoint farm solution or sandboxed solution. SharePoint 对象模型的一些部分(主要是与自定义 SharePoint 管理和安全性相关)无法从客户端访问。Some parts of the SharePoint object model, mainly connected with customizing SharePoint administration and security, are not accessible from clients. 只有在 SharePoint 服务器上运行的自定义代码才能访问它们,而 SharePoint 加载项中禁止使用自定义服务器端代码。Only custom code running on the SharePoint server can access them, and custom server-side code is not allowed in a SharePoint Add-in. (借助大量客户端对象模型和 REST/OData 服务,SharePoint 加载项可以执行几乎所有面向最终用户的 SharePoint 扩展。)(A rich set of client object models and a REST/OData service make it possible for SharePoint Add-ins to do almost any end-user-oriented SharePoint extension.)

若要详细了解如何确定使用经典解决方案还是使用加载项,请参阅 SharePoint 加载项与 SharePoint 解决方案对比For more information about deciding between classic solutions and add-ins, see SharePoint Add-ins compared with SharePoint solutions. 在 SharePoint 中选择正确的 API 集一文也有助于做出此决定。Also helpful for making this decision is Choose the right API set in SharePoint.

SharePoint 加载项的关键设计元素Key elements in the design of SharePoint Add-ins

设计 SharePoint 加载项时,需要选择三大类的设计选项。Three major categories of choices need to be made when a SharePoint Add-in is designed. 一如既往,应用设计需要有所取舍;选择的一类选项可能会限制另一类选项。As always, application design involves trade-offs; choices you make in one category may limit your options in another. 并不是每种可能的选项组合都可行。Not every possible combination of choices is feasible.

  • 托管: 根据部署和托管方式,SharePoint 加载项可分为两大类:Hosting: SharePoint Add-ins can be divided into two major types based on how they are deployed and hosted.

    • 提供程序托管加载项的主要数据存储和业务逻辑由开发人员部署和托管在 SharePoint 外的服务器中,或由开发人员提供的云帐户进行部署和托管。Provider-hosted add-ins have their primary data storage and business logic deployed and hosted by you—the developer—outside of SharePoint in servers or a cloud account that you provide. 开发人员负责强制隔离购买加载项的各个客户的帐户。You are responsible for enforcing isolation between the accounts of the various customers who purchase your add-in. 此类加载项也可以有 SharePoint 组件。Such add-ins can have SharePoint components too. 它们托管在客户的 SharePoint 场中。These are hosted in the customer's SharePoint farm. 使用此类加载项,可以最灵活地选择其他类别的设计选项。This type of add-in provides you with the most flexibility in the other categories of design choices. 此外,还可以对外部数据、逻辑和 Web 用户界面 (UI) 使用非 Microsoft 平台。It also enables you to use non-Microsoft platforms for the external data, logic, and web user interface (UI). (在提供程序托管加载项类别中,还需要区分远程组件与 SharePoint 场位于同一企业防火墙中的加载项和远程组件在此防火墙之外的加载项。(Within the category of provider-hosted add-ins, you also need to distinguish between add-ins whose remote components are within the same corporate firewall as the SharePoint farm and those whose remote components are outside of that firewall. 这两个方案的授权系统不同,这反过来又导致访问 SharePoint 数据时使用的编程语言不同。)The authorization systems for these two scenarios are different, which, in turn, makes a difference in which programming language you use to access the SharePoint data.)

    • SharePoint 托管的加载项完全由 SharePoint 组件(如列表、内容类型、工作流和 Web 部件)组成,它没有外部组件。有关可包含在 SharePoint 加载项中的 SharePoint 组件的类型的详细信息,请参阅 SharePoint 中的主机 Web、加载项 Web 和 SharePoint 组件SharePoint-hosted add-ins consist entirely of SharePoint components, such as lists, content types, workflows, and web parts. There are no external components. For more information about the kinds of SharePoint components that can be included in SharePoint Add-ins, see Host webs, add-in webs, and SharePoint components in SharePoint.

    若要详细了解 SharePoint 加载项托管选项,请参阅选择用于开发和托管 SharePoint 加载项的模式For more detailed information about the hosting options of SharePoint Add-ins, see Choose patterns for developing and hosting your SharePoint Add-in.

  • 连接: SharePoint 支持对数据执行三种安全的创建/读取/更新/删除 (CRUD) 操作。Connectivity: SharePoint supports three kinds of secure create/read/update/delete (CRUD) access to data.

    若要详细了解 SharePoint 加载项中的数据存储和数据访问,请参阅 SharePoint 加载项中的数据存储SharePoint 加载项的安全数据访问和客户端对象模型在 SharePoint 中处理外部数据For more information about data storage and access in SharePoint Add-ins, see Data storage in SharePoint Add-ins, Secure data access and client object models for SharePoint Add-ins, and Work with external data in SharePoint.

  • UI: 可通过三种方式在 SharePoint 中显示 SharePoint 加载项:至少,所有加载项都会显示在一个完整的网页中。或者,也可以通过加载项部件显示加载项,以及通过菜单项或功能区按钮显示加载项。有关详细信息,请参阅 SharePoint 加载项的 UX 设计UI: There are three ways to surface a SharePoint Add-in in SharePoint: at a minimum, all add-ins are surfaced in a full webpage. Optionally, an add-in can also be surfaced through an add-in part, and through a menu item or ribbon button. For more information, see UX design for SharePoint Add-ins.

备注

客户可以将 SharePoint 加载项安装到租赁中的多个网站集,也可以安装到各个网站。SharePoint Add-ins can be installed by your customers to multiple site collections in a tenancy, or on a website-by-website basis. 前者称为“租户范围加载项”。如果希望客户可以使用租户范围选项,不得添加自定义功能区按钮或加载项部件。The former are called tenant-scoped add-ins. If you want your customers to have the tenant-scoped option, you may not include a custom ribbon button or an add-in part. 有关详细信息,请参阅 SharePoint 加载项的租赁和部署范围For more information, see Tenancies and deployment scopes for SharePoint Add-ins.

体系结构层Architectural tiers

考虑外接程序体系结构选项的另一个方法是将外接程序视为具有三个逻辑层:UI、业务逻辑和数据访问。每一层都有多个实现选项;再次重申,对某一层做出的选择将限制对其他层的选择。下表介绍了外接程序的远程组件和 SharePoint 组件的一部分选项及其用途。Another way to think about your add-in architecture options is to think of the add-in as having three logical tiers: the UI, the business logic, and the data access. Each layer has multiple implementation options; again, choices made for one layer limit the options for others. The following tables describe some of the options, and their uses, for the remote components of an add-in and the SharePoint components.

提供程序托管的外接程序的远程组件:每一层的选项Remote components in provider-hosted add-ins: options for each tier

Tier 选项Options 适用于Good for
UIUI 以 Azure Web 角色托管的 ASP.NET 表单或 MVC 应用中的 ASP.NET 页ASP.NET pages in an ASP.NET form or MVC application that is hosted in an Azure web role 充分发挥 ASP.NET 开发人员的技能水平Leveraging the skills of an ASP.NET development staff
使用 JavaScript 的 HTML 5 页面HTML 5 page with JavaScript 丰富用户界面Rich user interface
PHP 或非 Microsoft 云服务中托管的其他类型网页PHP or other kind of webpage hosted in a non-Microsoft cloud service 将非 Microsoft 应用集成到 SharePoint 中Integrating non-Microsoft applications into SharePoint
Windows Phone 应用中的 SilverlightSilverlight in a Windows Phone app 移动访问 SharePoint 数据,并集成地理位置数据和推送通知Mobile access to SharePoint data and integration with geolocation data and push notifications
业务逻辑Business logic 客户端 JavaScriptClient-side JavaScript UI 逻辑和轻量级业务逻辑;通过 JavaScript 客户端对象模型访问 SharePoint 数据UI logic and light business logic; accessing SharePoint data through the JavaScript client object model
Microsoft Azure 辅助角色A Microsoft Azure worker role 占用大量处理器资源的功能;通过 .NET Framework 客户端对象模型访问 SharePoint 数据Processor-intensive functionality; accessing SharePoint data through the .NET Framework client object model
远程 Web 服务A remote web service 占用大量处理器资源的功能;通过 .NET Framework 客户端对象模型访问 SharePoint 数据Processor-intensive functionality; accessing SharePoint data through the .NET Framework client object model
DataData SQL AzureSQL Azure 功能齐全的关系数据Full-featured relational data
Azure 表存储Azure Table storage 应用设置和其他元数据Application settings and other metadata
Azure Blob 存储Azure Blob storage 存储大型文件Storage of large files
非 Microsoft 云服务A non-Microsoft cloud service 利用基于非 Microsoft 平台的现有数据源Leveraging existing data sources that are based on non-Microsoft platforms
开发人员自己的服务器上的数据库A database on the developer's own server 提供程序托管和开发人员控制的租赁隔离Provider-hosting and developer control of tenancy isolation

SharePoint 组件:每层可用的选项SharePoint components: options for each tier

Tier 选项Options 适用于Good for
UIUI 加载项网页上的 SharePoint 列表和库的自定义视图Custom views of SharePoint lists and libraries on add-in webpages 最大限度地与 SharePoint 外观和行为集成Maximizing integration with SharePoint appearance and behavior
托管在加载项网页上的 Web 部件中(或 标记内)的 Silverlight 应用Silverlight application hosted in a web part (or within tags) on an add-in webpage 利用现有 Silverlight 开发经验;丰富用户界面Leveraging existing Silverlight development experience; rich user interface
业务逻辑Business logic SharePoint 工作流A SharePoint workflow 实现业务流程Implementing business processes
使用 SharePoint 跨域库作为补充的客户端 JavaScriptClient-side JavaScript supplemented with the SharePoint cross-domain library 访问加载项 Web 中的 SharePoint 数据;访问租赁内其他网站中的数据Accessing SharePoint data in the add-in web; accessing data in other websites within the tenancy
远程事件处理程序A remote event handler 使用外部托管的逻辑处理 SharePoint 列表和库中的 CRUD 事件Handling CRUD events in SharePoint lists and libraries using externally hosted logic
数据Data 通过协作应用标记语言 (CAML) 或 LINQ 查询以及 SharePoint 客户端对象模型之一查询到的 SharePoint 列表和库SharePoint lists and libraries that are queried through Collaborative Application Markup Language (CAML), or LINQ queries with one of the SharePoint client object models 利用现有 SharePoint 和 .NET Framework 开发经验Leveraging existing SharePoint and .NET Framework development experience
通过 SharePoint REST/OData Web 服务查询的 SharePoint 列表和库SharePoint lists and libraries that are queried through the SharePoint REST/OData web service 访问非 Microsoft 平台中的 SharePoint 数据;利用现有 OData 查询体验Accessing SharePoint data from non-Microsoft platforms; leveraging existing OData query experience
BCS 模型A BCS Model 在 SharePoint 中以 SharePoint 列表形式显示外部数据Surfacing external data in SharePoint as a SharePoint list

做出设计决策时要考虑的因素Factors to consider when making your design decisions

SharePoint 外接程序模型使单个决策树无法实现的很多功能都成为了现实。下面是在构造 SharePoint 外接程序的体系结构时要考虑的一些最重要的因素。The SharePoint Add-in model enables so many possibilities for design that a simple decision tree is not possible. The following are some of the most important factors to consider when constructing the architecture of a SharePoint Add-in.

  • 最重要的当然是要为客户提供的功能,即用例。Most importantly, of course, is the functionality you want to make available to customers—the use cases. 例如,如果加载项包括占用大量处理器资源的功能(如将视频文件转换为其他视频格式),这就表示有必要创建提供程序托管加载项,即处理工作是在服务器之一或 Azure 辅助角色上完成。For example, if your add-in includes processor-intensive functions, such as converting video files to another video format, that would be an argument for creating a provider-hosted add-in in which the processing is done on one of your servers or an Azure worker role.

  • 由于提供程序托管的外接程序(一种 SharePoint 外接程序)要求您(或您的客户)托管非 SharePoint 组件并强制实现租户隔离,因此您需要考虑是否让硬件和 IT 员工执行此操作(或是否让您的目标客户执行此操作)。Because one kind of SharePoint Add-in, provider-hosted add-ins, requires you (or your customer) to host the non-SharePoint components and to enforce tenant isolation, you need to consider whether you have the hardware and IT staff to do this (or whether your targeted customers do).

  • 您的目标客户是哪些也是一个重要的考虑事项。如果您的所有外接程序都是在内部使用的(也就是说,您没有外部客户),那么提供程序托管的外接程序的实现和维护将比您有外部客户时容易得多。如果您打算公开出售外接程序,则还应考虑是将外接程序销售给具有 SharePoint Online 帐户的企业,销售给具有其自己的 SharePoint 场的企业,还是具有这两者的企业。Which customers you are targeting is also a crucial consideration. If all your add-ins will be used in-house (that is, you have no external customers) or used by a single customer, provider-hosted add-ins are significantly easier to implement and maintain than when you have external customers or multiple customers will use the add-in. If you intend to sell the add-in publicly, you should also consider whether you will market it to businesses that have SharePoint Online accounts or those with their own SharePoint farms, or both.

  • 您还应考虑您的现有技能或您的开发员工的技能。例如,如果您是一个有经验的 ASP.NET 开发人员,则可以考虑创建远程 Web 应用程序以及在 ASP.NET 页上显示 Sharepoint 列表数据。另一方面,如果您是一个有经验的 SharePoint 开发人员,则可以考虑将自定义 SharePoint 列表和网站页与 JavaScript 结合使用来执行处理。You should also consider your existing skills or the skills of your development staff. For example, if you are an experienced ASP.NET developer, that would be a point in favor of creating a remote web application and surfacing SharePoint list data on an ASP.NET page. On the other hand, if you are an experienced SharePoint developer, that would be a point in favor of using a custom SharePoint list and site page, with JavaScript to perform processing.

另请参阅See also