Partager via


List-Backed Configuration Quick Start

Overview

In some environments, developers and IT professionals might prefer to manage configuration settings through lists rather than through property bags and persisted objects. (The SharePoint Guidance Library implements property bags and persisted objects by default.). The 2010 release of Designing SharePoint Applications enables you to manage application setting configurations. It also provides several classes that you can use to implement a list-backed approach for storing configuration settings.

This quick start explains how to create and register a list-backed application settings manager and provides a sample implementation. To understand this quick start, you should first review the chapter on the Application Setting Manager.

The example implementation stores configuration settings in two lists. Site collection (SPSite) and site settings (SPWeb) are stored in a list at the root Web site of the site collection in which they are located. Farm and Web application settings apply across site collections, and therefore these settings need to be located in a single central site collection.

Implementation Details

To manage settings at specific levels, a custom application settings manager must replace the property bags with a list-backed property bag. The collection of property bags are managed by a configuration hierarchy.

To move to a list-backed implementation you will:

  1. Create a configuration hierarchy that uses list-backed property bags.
  2. Derive a configuration manager to use this hierarchy.
  3. Derive a hierarchical configuration to use this hierarchy.
  4. Register the configuration manager and hierarchical configuration implementations with the service locator.

The SharePoint Guidance Library provides most of the implementation code required to implement a list-backed solution, including:

  • ListBackedPropertyBag – This class implements a property bag that stores configuration in a list. The implementation assumes that the list for storing settings is located in the root Web site of the site collection which contains the site. This property bag can be used within a sandbox as well.
  • ListBackedUrlPropertyBag – This class implements a property bag that stores configuration in a list. The implementation assumes that the list for storing settings is located at the root Web site of a site collection identified by the URL provided. Updating the settings for a list in a different site collection requires enabling unsafe updates. This class cannot be used in the sandbox because sandboxed solutions cannot perform unsafe updates.
  • ConfigurationList – This class implements the logic for creating the list that will contain the settings. It also contains the logic for looking up and storing values in that list. The ConfigurationList contains a context ID (for example, the Site.ID that uniquely identifies a site), a key, and a value. When a value is looked up, both the context ID and the key identify the value to retrieve.
  • PropertyBagHierarchy – This class provides the base implementation for a property bag hierarchy. It contains the collection of property bags to use in the hierarchy, and implements the interface expected by the configuration manager and hierarchical manager for any property bag.
  • HierarchicalConfig – This class provides the logic for performing a hierarchical lookup of application settings.
  • ConfigManager – This class provides the logic for reading and writing settings for a specific property bag.

The quick start implements the following classes to realize list-backed application settings management:

  • ListBackedConfigHierarchy – This class derives from the PropertyBagHierarchy class. The implementation creates list-backed property bags for the Web, site, Web application, and farm, and then adds these property bags to the collection managed by the base class.
  • ListBackedHierarchicalConfig – This class overrides the method for creating the configuration hierarchy, and returns the ListBackedConfigHierarchy in place of the default implementation.
  • ListBackedConfigManager – This class overrides the method for creating the configuration hierarchy, and returns the ListBackedConfigHierarchy in place of the default implementation.
  • CentralSiteConfig – This class manages the configuration setting for the URL location of the site that contains the list for storing Web application and farm settings.

Packaging and Deployment

The quick start is packaged as a site-scoped feature. The feature implements a feature event receiver, which takes the following actions:

  • FeatureInstalled – This action creates the central list for storing configuration settings for the farm and Web application level the list does not already exist. The ConfigurationList implementation contains a method, called EnsureConfigurationList, that creates the site columns, content type, and list at the central location if they do not already exist. It uses the CentralSiteConfig class to store the URL for the central site.
  • FeatureActivated – This action uses the EnsureConfigurationMethod to create the list for managing the site and Web–level settings. It creates the list at the root Web site of the site collection, if it does not already exist. It uses the service locator to register the implementations for the IHierarchicalConfig and IConfigManager interfaces as ListBackedHierarchicalConfig and ListBackedConfigManager, respectively. These classes are at the site level.
  • FeatureDeactivated – This action removes the registration of the ListBackedHierarchicalConfig and ListBackedConfigManager from the service locator.

Demonstration

This quick start includes a simple visual Web Part—named ListBackedConfigurationTests—that demonstrates how to implement a list-backed approach for managing configuration settings. This Web Part demonstrates running through settings and getting values at different levels when a button is pushed. It then displays the results, as shown by the following diagram.

Demonstration of list-backed implementation results

Ff798463.8447a7f1-2a00-4cc9-b5f7-683ae121bf92(en-us,PandP.10).png