示例#1
0
        void Start()
        {
            Logger.text = string.Empty;
            Debug.Log("Starting IOC Test");

            Injector.ConfirmInit();
            Injector.Subscribe(this);

            var inst5 = Injector.GetFirst <ExampleExport2>();

            Assert(() => inst5 != null, "InjectorInitialized");

            Injector.AddExport(ExampleExport.Create());

            var inst = Injector.GetFirst <ExampleExport>();

            Assert(() => inst != null, "GetFirst Class");

            var inst2 = Injector.GetFirst <IExampleExport>();

            Assert(() => inst2 != null, "GetFirst Interface");
            Assert(() => Importer1 != null, "Import Single");
            Assert(() => Importer2 != null, "Import IEnumerable");
            Assert(() => Importer3 != null, "Import Array");

            Injector.RemoveExport(inst2);
            var inst3 = Injector.GetFirst <IExampleExport>();

            Assert(() => inst3 == null, "Removed");
            Assert(() => Importer1 == null, "Import Single");
            Assert(() => Importer2 == null || !Importer2.Any(), "Import Multiple");

            Injector.AddExport(ExampleExport.Create());
            Injector.AddExport(ExampleExport.Create());
            Injector.AddExport(ExampleExport.Create());
            Injector.AddExport(ExampleExport.Create());
            Injector.AddExport(ExampleExport.Create());

            var inst4 = Injector.GetAll <IExampleExport>();

            Assert(() => inst4.Count() == 5, "Get All");

            Assert(() => Importer1 != null, "Import Single");
            Assert(() => Importer2.Count() == 5, "Import IEnumerable");
            Assert(() => Importer3.Length == 5, "Import Array");

            Debug.Log("All Done");
        }