Registering services on Site Collection Level

Jun 5, 2010 at 8:31 AM
Hi, does the current drop support registering a service att Site Collection level? I've tried registering a service in feature activator using the Site property and then requesting the service from a Web Part without luck. Farm scoped services works fine. According to the docs the service should first be located in the SC and if not present there it should check the farm level. Just wondering if it is supported in this drop and if I should bother debug or not? /WW
Jun 5, 2010 at 2:09 PM

There is a regression bug that crept into this drop with saving values at the site collection and web levels that is preventing the setting from actually being persisted.  This fell out of a refactoring we did to make web app and farm level operations more resilient under heavy load (with SPUpdatedConncurrencyException retry logic) that came from our stress testing. 

To fix it right now, you need to go to SPWebPropertyBag, and in the indexer property set method, add a call to update after setting.

       public string this[string key]
        {
        
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            get
            {
                return this.web.AllProperties[BuildKey(key)] as string;
            }
            [SharePointPermission(SecurityAction.InheritanceDemand, ObjectModel = true)]
            [SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]
            set
            {
                if (this.Contains(key))
                {
                    this.web.SetProperty(BuildKey(key), value);
                }
                else
                {
                    this.web.AddProperty(BuildKey(key), value);
                }
                Update();
            }
        }
You need to the same to the remove operation:
        public virtual void Remove(string key)
        {
            string fullKey = BuildKey(key);

            if (this.Contains(key))
            {
                this.web.DeleteProperty(fullKey);
                Update();
            }
        }
Jun 5, 2010 at 3:44 PM

Awesome, thanks!

Giving the Service Locator a shout-out in the SharePoint 2010 Web Parts in Action book I'm writing (http://www.sharepointwebpartsinaction.com/)

/WW

Jun 5, 2010 at 4:04 PM

Excellent, thanks!   Let us know if you need anything else.

Thanks,
Chris