public void PolymorphismWorks() { // setup _context.DeclareQualified <Door>("goldenDoor"); _context.Declare <Palace>(); _context.Declare(Janitor.MakeJanitor()); // when _context.Resolve(); var janitor = _context.Get <Janitor>(); // then // a palace also is a house, so this janitor gets the palace Assert.IsNotNull(janitor.House); }
/// <summary> /// Scans the current scene for MonoBehaviours that derive from the given type and declares them in the /// dependency context. /// </summary> /// <param name="context">the context into which the classes should be declared.</param> /// <param name="qualify">if true, the scanned component will be declared with their name as qualifier. /// If false, they will be declared without a qualifier. /// </param> private static void DeclareMonoBehavioursFromScene <T>(DependencyContext context, bool qualify) where T : MonoBehaviour { var type = typeof(T); var results = UObject.FindObjectsOfType <T>(); foreach (var result in results) { var qualifier = ""; if (qualify) { qualifier = result.name; } context.DeclareQualified(type, qualifier, result); } }