Registering type mappings at site collection level, and in sandbox

Dec 7, 2011 at 1:12 PM
Edited Dec 7, 2011 at 1:16 PM

Hi, I can't seem to get service locator type registering working at site collection level. I am using latest download from

First, basic question: we would like to use service locator also in sandbox and in multiple-vendor environments, so we are trying to register types at site collection level instead of farm (to avoid sandboxing issue and to avoid possible mixups when several vendors are using SPG in the farm). Should using service locator in sandbox be possible this way?

Second, the actual issue. I have a site collection scoped feature, where I try to register the types at site collection level. I get no errors and I can see typemappings added to the collection.

However when I later come back to retrieve instance, my registered type is not there.

Should this work in this build?

Code I try to use for registering our ICustomCache interface in FeatureActivated:

IServiceLocator serviceLocator = SharePointServiceLocator.GetCurrent();
IServiceLocatorConfig config = serviceLocator.GetInstance<IServiceLocatorConfig>();
config.Site = siteColl;
config.RegisterTypeMapping<ICustomCache, CustomCache>();

Code I try to use to get instance of ICustomCache (but at this point mapping does not exist in typeMappingsDictionary):

IServiceLocator loc = SharePointServiceLocator.GetCurrent();
ICustomCache cache = loc.GetInstance();

If I change my feature scope to Farm instead of Site, and my feature event to FeatureInstalled instead of FeatureActivated, and remove use of config.Site, then it works. But I would prefer the site collection option.



Dec 8, 2011 at 8:30 AM

Update: got this working now at site collection level by adding this line to the type registration code in the feature receiver: