private static void DiscoverInstallers(ZenjectServiceConfiguration configuration, HashSet <ZenjectServiceInstaller> installerSet, List <ZenjectServiceInstaller> installerList, HashSet <ZenjectServiceConfiguration> processedConfigurations)
        {
            if (configuration == null)
            {
                return;
            }

            if (!processedConfigurations.Add(configuration))
            {
                return;
            }

            foreach (var installer in configuration.Installers.Reverse())
            {
                if (installer == null)
                {
                    continue;
                }

                if (installerSet.Add(installer))
                {
                    installerList.Add(installer);
                }
            }

            foreach (var inheritedConfiguration in configuration.InheritedConfigurations.Reverse())
            {
                DiscoverInstallers(inheritedConfiguration, installerSet, installerList, processedConfigurations);
            }
        }
        private void Refresh()
        {
            this.serializedObject.ApplyModifiedProperties();

            this.targetConfigurationObject = this.target as ZenjectServiceConfiguration;
            this.targetInstallerComponents = AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(this.target))
                                             .OfType <ZenjectServiceInstaller>()
                                             .ToDictionary(x => x.TargetService);
            this.targetActiveInstallers = new HashSet <ZenjectServiceInstaller>(this.targetConfigurationObject.Installers);
            //this.targetInheritedInstallers = new HashSet<ZenjectServiceInstaller>(this.targetConfigurationObject.InheritedInstallers);
            this.serviceDependentsLookup       = ZenjectServiceUtility.BuildServiceDependentsLookup(this.targetConfigurationObject.AllInstallers);
            this.sortedServiceDependentsLookup = this.serviceDependentsLookup.ToDictionary(
                entry => entry.Key,
                entry => entry.Value
                .OrderBy(group => group.TitleWithNamespace, ServiceGroupTitleComparer.Instance)
                .ToArray()
                );

            this.serviceEntries = this.discoveredServices
                                  .Select(CreateServiceEntry)
                                  .OrderBy(entry => entry.Descriptor.ServiceType.Name)
                                  .GroupBy(service => service.Descriptor.ServiceType.Namespace)
                                  .Select(group => new ServiceEntryGroup {
                Title   = !string.IsNullOrEmpty(group.Key) ? group.Key : "Global Namespace",
                Entries = group.ToArray()
            })
                                  .OrderBy(group => group.Title, ServiceGroupTitleComparer.Instance)
                                  .ToArray();
        }
Exemplo n.º 3
0
 private static void VerifyCyclicInheritance(ZenjectServiceConfiguration serviceConfiguration)
 {
     if (serviceConfiguration.HasCyclicInheritance())
     {
         throw new InvalidOperationException("One or more inherited service configurations inherit the same configuration!");
     }
 }
        private static IEnumerable <ZenjectServiceInstaller> DiscoverInstallers(ZenjectServiceConfiguration configuration)
        {
            var installerSet            = new HashSet <ZenjectServiceInstaller>();
            var installerList           = new List <ZenjectServiceInstaller>();
            var processedConfigurations = new HashSet <ZenjectServiceConfiguration>();

            DiscoverInstallers(configuration, installerSet, installerList, processedConfigurations);
            installerList.Reverse();
            return(installerList);
        }
        private static IEnumerable <ZenjectServiceInstaller> DiscoverInheritedInstallers(ZenjectServiceConfiguration configuration)
        {
            var installerSet            = new HashSet <ZenjectServiceInstaller>();
            var installerList           = new List <ZenjectServiceInstaller>();
            var processedConfigurations = new HashSet <ZenjectServiceConfiguration>();

            processedConfigurations.Add(configuration);

            foreach (var inheritedConfiguration in configuration.InheritedConfigurations.Reverse())
            {
                DiscoverInstallers(inheritedConfiguration, installerSet, installerList, processedConfigurations);
            }
            installerList.Reverse();
            return(installerList);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Installs a given Zenject service to a given Zenject container.
        /// </summary>
        /// <param name="container">Inversion of control container.</param>
        /// <param name="serviceConfiguration">The target service configuration.</param>
        /// <exception cref="System.InvalidOperationException">
        /// <list type="bullet">
        /// <item>If one or more inherited configurations inherit the same configuration!</item>
        /// <item>If multiple installers have been specified for the same service (overloaded installers).</item>
        /// <item>If one or more dependent services do not have installers.</item>
        /// </list>
        /// </exception>
        public static void Install(DiContainer container, ZenjectServiceConfiguration serviceConfiguration)
        {
            VerifyCyclicInheritance(serviceConfiguration);

            Install(container, serviceConfiguration.AllInstallers.Cast <IServiceInstaller>());
        }