Пример #1
0
        private static void ResolveInstanceDependencies(DependencyData dependencyData)
        {
            var instance     = dependencyData.instance;
            var dependencies = dependencyData.dependencies;

            for (int i = dependencies.Count - 1; i >= 0; i--)
            {
                var dependency = dependencies[i];
                if (DependencyRegistry.Registry.ContainsKey(dependency.FieldType))
                {
                    dependencyData.ResolveDependency(dependency, DependencyRegistry.Registry[dependency.FieldType].instance);
                }
                else
                {
                    Debug.LogError($"Failed to resolve dependency of type {dependency.FieldType} for {instance.GetType()}");
                }
            }
        }
Пример #2
0
        private static void AddToRegistry <TImplementation>() where TImplementation : class
        {
            if (Registry.TryGetValue(typeof(TImplementation), out var existingEntry) && existingEntry.instance != null)
            {
                return;
            }

            var newDependency = new DependencyData(typeof(TImplementation));

            Registry[typeof(TImplementation)] = newDependency;

            Injector.ResolveDependencies(newDependency);

            if (newDependency.instance is IPostConstructable postConstructable)
            {
                postConstructable.PostConstruct();
            }
        }
Пример #3
0
 public static void ResolveDependencies(DependencyData dependencyData)
 {
     ResolveInstanceDependencies(dependencyData);
     ResolveExistingDependencies(dependencyData.instance);
 }