Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        private IServiceLocator RefreshServiceLocatorInstance(SPSite site)
        {
            var siteserviceLocatorConfig = GetServiceLocatorConfig(site);
            SiteLocatorEntry entry       = siteLocators[site.ID];

            //only update if changed since last time we loaded...
            if (siteserviceLocatorConfig.LastUpdate > entry.LoadTime)
            {
                if (entry.locator.GetType() == typeof(ActivatingServiceLocator))
                {
                    // get any mappings added programmatically.  Assume this behavior is unique to
                    //Activating service locator, so ignore if not activating.
                    var activatingLocator = (ActivatingServiceLocator)entry.locator;
                    activatingLocator.Refresh(GetDefaultTypeMappings(),
                                              FarmLocatorConfig.GetTypeMappings(),
                                              entry.SiteMappings,
                                              siteserviceLocatorConfig.GetTypeMappings());
                }
                else
                {
                    IServiceLocatorFactory factory = GetServiceLocatorFactory(this.FarmLocatorConfig.GetTypeMappings());
                    SetupCustomLocator(factory, entry.locator, siteserviceLocatorConfig.GetTypeMappings());
                }
                entry.SiteMappings = siteserviceLocatorConfig.GetTypeMappings();
            }

            entry.LoadTime = DateTime.Now;
            return(entry.locator);
        }
Ejemplo n.º 4
0
        private static IServiceLocatorFactory GetServiceLocatorFactory(IEnumerable <TypeMapping> configuredTypeMappings)
        {
            // Find configured factory. If it's there, creat it.
            IServiceLocatorFactory factory = FindAndCreateConfiguredType <IServiceLocatorFactory>(configuredTypeMappings);

            // If there is no configured factory, then the ActivatingServiceLocatorFactory is the default one to use
            if (factory == null)
            {
                factory = new ActivatingServiceLocatorFactory();
            }

            return(factory);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
 private void SetupCustomLocator(IServiceLocatorFactory factory, IServiceLocator locator, IEnumerable <TypeMapping> siteMappings)
 {
     factory.LoadTypeMappings(locator, GetDefaultTypeMappings());
     factory.LoadTypeMappings(locator, FarmLocatorConfig.GetTypeMappings());
     factory.LoadTypeMappings(locator, siteMappings);
 }
Ejemplo n.º 7
0
 protected internal virtual DisabledInitializationEngine CreateDisabledInitializationEngine(IEnumerable <Assembly> assemblies, IAssemblyScanner assemblyScanner, HostType hostType, IServiceLocatorFactory serviceLocatorFactory)
 {
     return(new DisabledInitializationEngine(assemblies, assemblyScanner, hostType, serviceLocatorFactory));
 }
Ejemplo n.º 8
0
 public InitializationEngineFactory(IEnumerable <Assembly> assemblies, IAssemblyScanner assemblyScanner, IServiceLocatorFactory serviceLocatorFactory)
 {
     this.Assemblies            = assemblies ?? throw new ArgumentNullException(nameof(assemblies));
     this.AssemblyScanner       = assemblyScanner ?? throw new ArgumentNullException(nameof(assemblyScanner));
     this.ServiceLocatorFactory = serviceLocatorFactory ?? throw new ArgumentNullException(nameof(serviceLocatorFactory));
 }
 public TfsSearchProvider(IServiceLocatorFactory locatorFactory)
 {
     var collectionUri = locatorFactory.GetByName("TfsServiceLocator").Location;
     _collection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(collectionUri);
 }
Ejemplo n.º 10
0
 /// <summary>
 ///     Sets the current.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <exception cref="System.ArgumentNullException">factory</exception>
 public static void SetCurrent(IServiceLocatorFactory factory)
 {
     CurrentFactory = factory ?? throw new ArgumentNullException(nameof(factory));
 }
Ejemplo n.º 11
0
 public static void SetCurrent(IServiceLocatorFactory serviceLocatorFactory)
 {
     _serviceLocatorFactory = serviceLocatorFactory;
 }
        public DisabledInitializationEngine(IEnumerable <Assembly> assemblies, IAssemblyScanner assemblyScanner, HostType hostType, IServiceLocatorFactory serviceLocatorFactory) : base(serviceLocatorFactory, null, hostType, assemblies, assemblyScanner)
        {
            if (assemblies == null)
            {
                throw new ArgumentNullException(nameof(assemblies));
            }

            if (assemblyScanner == null)
            {
                throw new ArgumentNullException(nameof(assemblyScanner));
            }

            if (serviceLocatorFactory == null)
            {
                throw new ArgumentNullException(nameof(serviceLocatorFactory));
            }
        }