Overview

The project is setup internally according to the following diagram:

SPRepositoryArchitecture.png

Where an SPListItem is represented by an IContentType and it's values are stored in an IContentTypeDto.

First things first, what are the objects use to represent all this ?

SPRepositoryInheritance.png

The objects shown are the building blocks for our repository.

IFieldType

Implementations of this interface will know how to store and retrieve values from their corresponding SharePoint fields.

Current built-in field types include:
  • SimpleFieldType<T>
    • Returns a Value Type to represent the value (i.e. no Dto)
    • Can be used to represent a SPFieldText, SPFieldDateTime, SPFieldNumber
  • MultilineTextFieldType
    • To Represent an SPFieldMultilineText
  • SingleLookupFieldType
    • To represent a SPFieldLookup (single value)
  • MultiLookupFieldType
    • To represent a SPFieldLookup (multi value)
  • SingleTaxonomyFieldType
    • To represent a SPFieldTaxonomy (single value)
  • ...

The idea is to have all standard SharePoint field types represented by a FieldType class. Custom fields will have to have a custom FieldType class.

IFieldType interface

These FieldTypes all implement IFieldType:

public interface IFieldType<T>
    {
        Guid FieldId { get; }

        T GetValue(SPListItem item);
        void SetValue(SPListItem item, T value);
    }


Which means that the whole implementation of retrieving and updating the SharePoint field's value is abstracted by this class.

SimpleFieldType<T>

This is a generic implementation of the IFieldType interface and is sufficient for basic value type SharePoint fields like SPFieldText, which only stores a string. Other FieldTypes can inherit from this class to override the GetValue and SetValue methods, which is the only thing that is different for each FIeldType class and usually only necessary when the return value is a Dto.

IFieldTypeDto

All complex SharePoint objects like
  • SPFieldTaxonomyValue
  • SPFieldUserValue
  • SPFieldLookupValue
  • ...

are represented by a Dto. This is not fundamental to the Repository but it allow for better Testing since they can more easily be mocked than their SharePoint object counterparts.

Access

It is important to know that Dto's only have one property with a public setter for each representation of the same property. By duplicate property I mean any property that is really the same as another property except it displays the value differently.

E.g.:
  • SPFieldTaxonomyValue.Label
  • SPFieldTaxonomyValue.TermGuid

in this case the TaxonomyFieldDto only exposes a setter for the TermGuid, since the label is just another way of representing the value. The Label can still be accessed through the Dto getter property.

IContentType

A container for IFieldType properties

    public interface IContentType<T> where T : IContentTypeDto
    {
        T Get(object item);
        void Update(object item, T dto);
        string GetContentTypeIdDefinition();
    }


The classes implementing the IContentType represent an SPListItem of a certain SPContentType.

Similar to the IFieldTypes, the idea is to have all standard SharePoint Content Types represented by an IContentType implementation.

The IContentType classes abstract the retrieval and updating of all the fields contained in an SPContentTpye.

An IContentType implementation has knowledge of the SPContentTypeId for the SPContentType it represents, it knows it's accompanying IContentTypeDto implementation (through the use of generics), and it knows what FieldTypes it contains. Each of it's member FieldTypes is instantiated and connected through its corresponding SPField through the use of the FieldId guids.

IContentTypeDto

Similary built up as the IContentType class, containing IFieldDto's or Value Types instead of IFieldTypes. It has no knowledge of SharePoint or any of the Repository classes and only knows about field values.

Any interaction with the IContentTypDto back to SharePoint will happen through the corresponding IContentType implementation.

Usually this will be abstract through an SPGenericRepositoryImplementation.

SPGenericRepository

Don't let the name mistake you, this is not a standard SharePoint object, but a class from this project and the 'SP' indicates it communicates with SharePoint (as any repository ideally is an abstraction off the underlying DateSource).

SPGenericRepository is an implementation of the IRepository interface:

public interface IRepository<TT, TD>
        where TT : IContentType<TD>, new()
        where TD : class, IContentTypeDto
    {
        IEnumerable<TD> GetAll();

        TD Get(int id);

        void Update(TD dto);
        void Create(TD dto);

        void Delete(TD dto);
        void Delete(int id);
    }


As you can see, the interface defines all the basic interaction you can do on a DataSource.

The SPGenericRepository class implements this interface through the use of generics, making it the most basic repository that can be used for an SharePoint list interaction (as the SPList is the real underlying datasource of this class).

Look up the Quick-Start documentation for an example of its use.

Last edited Nov 1, 2013 at 10:19 AM by cverhelst, version 8