public AutoBindInstaller(CompositionRoot compRoot) { Assert.That(!(compRoot is GlobalCompositionRoot), "You cannot use AutoBindInstaller from within a global installer"); _compRoot = compRoot; }
public static IEnumerable <ZenjectResolveException> ValidateInstallers(CompositionRoot 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 void Initialize(CompositionRoot compRoot) { _root = compRoot.gameObject; }
static bool ValidateCompRoot(CompositionRoot 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; }