public override void InstallBindings() { foreach (var autoBinding in SceneCompositionRoot.GetSceneRootObjects(_compRoot.gameObject.scene) .SelectMany(x => x.GetComponentsInChildren <ZenjectAutoBinding>())) { if (autoBinding == null) { continue; } var component = autoBinding.Component; var bindType = autoBinding.BindType; if (component == null) { continue; } if (bindType == ZenjectAutoBinding.BindTypes.ToInstance || bindType == ZenjectAutoBinding.BindTypes.ToInstanceAndInterfaces) { Container.Bind(component.GetType()).ToInstance(component); } if (bindType == ZenjectAutoBinding.BindTypes.ToInterfaces || bindType == ZenjectAutoBinding.BindTypes.ToInstanceAndInterfaces) { Container.BindAllInterfacesToInstance(component); } } }
static bool ValidateCompRoot(SceneCompositionRoot compRoot, DateTime startTime) { if (compRoot.Installers.IsEmpty()) { Log.Warn("Could not find installers while validating current scene"); // Return true to allow playing in this case return(true); } // Only show a few to avoid spamming the log too much var resolveErrors = ZenEditorUtil.ValidateInstallers(compRoot).Take(10).ToList(); foreach (var error in resolveErrors) { Log.ErrorException(error); } var secondsElapsed = (DateTime.Now - startTime).Milliseconds / 1000.0f; if (resolveErrors.Any()) { Log.Error("Validation Completed With Errors, Took {0:0.00} Seconds.", secondsElapsed); return(false); } Log.Info("Validation Completed Successfully, Took {0:0.00} Seconds.", secondsElapsed); return(true); }
static List <ZenjectResolveException> ValidateCompRoot(SceneCompositionRoot compRoot, int maxErrors) { if (compRoot.Installers.IsEmpty()) { return(new List <ZenjectResolveException>() { new ZenjectResolveException("Could not find installers while validating current scene"), }); } return(ValidateInstallers(compRoot).Take(maxErrors).ToList()); }
public static IEnumerable <ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot, GameObject rootGameObject) { var globalContainer = GlobalCompositionRoot.CreateContainer(true, null); var container = compRoot.CreateContainer(true, globalContainer, new List <IInstaller>()); foreach (var error in container.ValidateResolve( new InjectContext(container, typeof(IFacade), null))) { yield return(error); } var injectedGameObjects = rootGameObject != null?rootGameObject.GetComponentsInChildren <Transform>() : GameObject.FindObjectsOfType <Transform>(); // Also make sure we can fill in all the dependencies in the built-in scene foreach (var curTransform in injectedGameObjects) { foreach (var monoBehaviour in curTransform.GetComponents <MonoBehaviour>()) { if (monoBehaviour == null) { // fiBackupSceneStorage shows up sometimes for reasons I don't understand // but it's normal so ignore if (curTransform.name != "fiBackupSceneStorage") { Log.Warn("Found null MonoBehaviour on " + curTransform.name); } continue; } foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType())) { yield return(error); } } } foreach (var installer in globalContainer.InstalledInstallers.Concat(container.InstalledInstallers).OfType <IValidatable>()) { foreach (var error in installer.Validate()) { yield return(error); } } foreach (var error in container.ValidateValidatables()) { yield return(error); } }
public static IEnumerable<ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot, GameObject rootGameObject) { var globalContainer = GlobalCompositionRoot.CreateContainer(true, null); var container = compRoot.CreateContainer(true, globalContainer, new List<IInstaller>()); foreach (var error in container.ValidateResolve( new InjectContext(container, typeof(IFacade), null))) { yield return error; } var injectedGameObjects = rootGameObject != null ? rootGameObject.GetComponentsInChildren<Transform>() : GameObject.FindObjectsOfType<Transform>(); // Also make sure we can fill in all the dependencies in the built-in scene foreach (var curTransform in injectedGameObjects) { foreach (var monoBehaviour in curTransform.GetComponents<MonoBehaviour>()) { if (monoBehaviour == null) { // fiBackupSceneStorage shows up sometimes for reasons I don't understand // but it's normal so ignore if (curTransform.name != "fiBackupSceneStorage") { Log.Warn("Found null MonoBehaviour on " + curTransform.name); } continue; } foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType())) { yield return error; } } } foreach (var installer in globalContainer.InstalledInstallers.Concat(container.InstalledInstallers).OfType<IValidatable>()) { foreach (var error in installer.Validate()) { yield return error; } } foreach (var error in container.ValidateValidatables()) { yield return error; } }
public static IEnumerable <ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot) { var globalContainer = GlobalCompositionRoot.CreateContainer(true, null); var container = compRoot.CreateContainer(true, globalContainer, new List <IInstaller>()); foreach (var error in container.ValidateResolve(new InjectContext(container, typeof(IDependencyRoot), null))) { yield return(error); } // Also make sure we can fill in all the dependencies in the built-in scene foreach (var curTransform in compRoot.GetComponentsInChildren <Transform>()) { foreach (var monoBehaviour in curTransform.GetComponents <MonoBehaviour>()) { if (monoBehaviour == null) { Log.Warn("Found null MonoBehaviour on " + curTransform.name); continue; } foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType())) { yield return(error); } } } foreach (var installer in globalContainer.InstalledInstallers.Concat(container.InstalledInstallers)) { if (installer is IValidatable) { foreach (var error in ((IValidatable)installer).Validate()) { yield return(error); } } } foreach (var error in container.ValidateValidatables()) { yield return(error); } }
public static IEnumerable<ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot) { var globalContainer = GlobalCompositionRoot.CreateContainer(true, null); var container = compRoot.CreateContainer(true, globalContainer, new List<IInstaller>()); foreach (var error in container.ValidateResolve(new InjectContext(container, typeof(IFacade), null))) { yield return error; } // Also make sure we can fill in all the dependencies in the built-in scene foreach (var curTransform in compRoot.GetComponentsInChildren<Transform>()) { foreach (var monoBehaviour in curTransform.GetComponents<MonoBehaviour>()) { if (monoBehaviour == null) { Log.Warn("Found null MonoBehaviour on " + curTransform.name); continue; } foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType())) { yield return error; } } } foreach (var installer in globalContainer.InstalledInstallers.Concat(container.InstalledInstallers)) { if (installer is IValidatable) { foreach (var error in ((IValidatable)installer).Validate()) { yield return error; } } } foreach (var error in container.ValidateValidatables()) { yield return error; } }
public static IEnumerable <ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot) { return(ValidateInstallers(compRoot, null)); }
static bool ValidateCompRoot(SceneCompositionRoot compRoot, DateTime startTime) { if (compRoot.Installers.IsEmpty()) { Log.Warn("Could not find installers while validating current scene"); // Return true to allow playing in this case return true; } // Only show a few to avoid spamming the log too much var resolveErrors = ZenEditorUtil.ValidateInstallers(compRoot).Take(10).ToList(); foreach (var error in resolveErrors) { Log.ErrorException(error); } var secondsElapsed = (DateTime.Now - startTime).Milliseconds / 1000.0f; if (resolveErrors.Any()) { Log.Error("Validation Completed With Errors, Took {0:0.00} Seconds.", secondsElapsed); return false; } Log.Info("Validation Completed Successfully, Took {0:0.00} Seconds.", secondsElapsed); return true; }
static List<ZenjectResolveException> ValidateCompRoot(SceneCompositionRoot compRoot, int maxErrors) { if (compRoot.Installers.IsEmpty()) { return new List<ZenjectResolveException>() { new ZenjectResolveException("Could not find installers while validating current scene"), }; } return ValidateInstallers(compRoot).Take(maxErrors).ToList(); }
public static IEnumerable<ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot) { return ValidateInstallers(compRoot, null); }