List Repository Design
The repository's functionality is based on the principle of composition instead of on inheritance. In this model, instead of deriving from a base class, the SharePoint Guidance library provides components that make it easier for you to build your own repository implementation. The following diagram describes how these components can simplify the development of a repository.
Design of the list repository
The implementation contains an instance of a ListItemFieldMapper class. This class is not used directly by client code. Instead, you typically use it within methods of your repository to transfer information between the SharePoint list and the business entity. The implementation is a variation of a common pattern that is named DataMapper. For more information, see Data Mapper on Martin Fowler's Web site.
Because you typically do not retain an instance member for the CAMLQueryBuilder class, it is not strictly composed with your repository. It is closer to a utility class that simplifies the retrieval of information from a list. The CAMLQueryBuilder class, or an alternative such as CAML.NET, provides more readable code, compile-time validation, and error reduction compared to writing your own CAML queries.
Role of Service Locator and Repository Interface in Implementation
Using a repository improves an application's design by centralizing the business access logic, providing strong types for compile-time type checking and encapsulation, and decoupling business logic from SharePoint-specific dependencies. These are all significant benefits for code maintenance, correctness, and flexibility.
Although implementing the repository pattern is a recommended practice, even without service location, these patterns are typically used in conjunction with one another. Service location provides an additional layer of abstraction that hides the concrete implementation of the repository from the consuming business logic. When using service location, you retrieve an instance of the repository based on the defined interface. This means that, to use service location, you must define an interface and implement the interface for your repository. The Partner Portal application follows this pattern for all of its repositories.
For more information about the service locator, see The Service Locator Pattern.
Note
It is important to validate the data that is being persisted. When using SharePoint lists as a persistence mechanism, it is recommended to use list item event receivers such as ItemAdding and ItemUpdating to perform validation. These event receivers can cancel the add/update operation if the list item data is invalid.