How to: Remove a Type Mapping

The following procedure demonstrates how to remove a type mapping from the SharePoint Service Locator.

To remove a type mapping from the SharePoint Service Locator

  1. Add assembly references Microsoft.Practices.SharePoint.Common.dll and Microsoft.Practices.ServiceLocation.dll.

  2. Add the following using statements to the top of your source code file.

    using Microsoft.Practices.ServiceLocation;
    using Microsoft.Practices.SharePoint.Common.ServiceLocation;
    
  3. Declare an object of type IServiceLocator and set it to the value of the SharePointServiceLocator.Current property.

    IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
    
  4. Use the service locator to request an implementation of the IServiceLocatorConfig interface. The returned object contains the type mappings that are managed by the service locator.

    Note

    To remove a site collection-scoped type mapping, you must also set the Site property on the IServiceLocatorConfig instance.

    IServiceLocatorConfig typeMappings =  
     serviceLocator.GetInstance<IServiceLocatorConfig>();
    
  5. Call the IServiceLocator.RemoveTypeMapping method. The type parameter is the interface that your mapped class implements. Pass a null argument to remove a default unnamed mapping, or a string key to remove a named mapping.

    typeMappings.RemoveTypeMapping<IService1>(null);