/// <summary> /// Create a new instance of the service locator and possibly fill it with farm and /// site level mappings. /// </summary> /// <returns>The service locator instance for the site. Combines site and farm level mappings</returns> private IServiceLocator CreateServiceLocatorInstance(SPSite site) { IEnumerable <TypeMapping> configuredTypeMappings = this.FarmLocatorConfig.GetTypeMappings(); IServiceLocatorFactory factory = GetServiceLocatorFactory(configuredTypeMappings); var entry = new SiteLocatorEntry(); entry.LoadTime = DateTime.Now; IServiceLocatorConfig siteserviceLocatorConfig = GetServiceLocatorConfig(site); entry.SiteMappings = siteserviceLocatorConfig.GetTypeMappings(); entry.locator = factory.Create(); lock (syncRoot) { var farmLocator = this.GetCurrentFarmLocator(); if (farmLocator.GetType() == typeof(ActivatingServiceLocator)) { // call order is important, the mappings at the site will override the mappings at the service. factory.LoadTypeMappings(entry.locator, ((ActivatingServiceLocator)farmLocator).GetTypeMappings()); factory.LoadTypeMappings(entry.locator, entry.SiteMappings); } else { //since registering runtime registeration is a feature of activating service locator, we will //assume that if it is not an activating locator, it is not supporting runtime registration. SetupCustomLocator(factory, entry.locator, entry.SiteMappings); } siteLocators[site.ID] = entry; } return(entry.locator); }
/// <summary> /// Create a new instance of the service locator and possibly fill it with /// </summary> /// <returns></returns> private static IServiceLocator CreateServiceLocatorInstance() { // The SharePoint service locator has to have access to SPFarm.Local, because it uses the ServiceLocatorConfig // to store it's configuration settings. if (SPFarm.Local == null) { throw new NoSharePointContextException("The SharePointServiceLocator needs to run in a SharePoint context and have access to the SPFarm."); } // Retrieve the type mappings that are stored in config. ServiceLocatorConfig serviceLocatorConfig = new ServiceLocatorConfig(); IEnumerable <TypeMapping> configuredTypeMappings = serviceLocatorConfig.GetTypeMappings(); // Create the factory that can configure and create the service locator // It's possible that the factory to be used has been changed in config. IServiceLocatorFactory serviceLocatorFactory = GetServiceLocatorFactory(configuredTypeMappings); // Create the service locator and load it up with the default and configured type mappings IServiceLocator serviceLocator = serviceLocatorFactory.Create(); serviceLocatorFactory.LoadTypeMappings(serviceLocator, GetDefaultTypeMappings()); serviceLocatorFactory.LoadTypeMappings(serviceLocator, configuredTypeMappings); return(serviceLocator); }
/// <summary> /// Create a new instance of the service locator and possibly fill it with /// </summary> /// <returns></returns> private IServiceLocator CreateServiceLocatorInstance() { IEnumerable <TypeMapping> configuredTypeMappings = this.FarmLocatorConfig.GetTypeMappings(); // Create the factory that can configure and create the service locator // It's possible that the factory to be used has been changed in config. IServiceLocatorFactory serviceLocatorFactory = GetServiceLocatorFactory(configuredTypeMappings); // Create the service locator and load it up with the default and configured type mappings IServiceLocator serviceLocator = serviceLocatorFactory.Create(); serviceLocatorFactory.LoadTypeMappings(serviceLocator, GetDefaultTypeMappings()); serviceLocatorFactory.LoadTypeMappings(serviceLocator, configuredTypeMappings); return(serviceLocator); }