Пример #1
0
        public void SetContextWithSetterTest()
        {
            var container = new ShandyGecko.ShandyGeckoDI.GeckoContainer();
            var context   = new ShandyGecko.ShandyGeckoDI.Context();

            container.RegisterInstance(new TestClass()).SetContext(context);
            Assert.AreEqual(1, context.ContainerRegistries.Count);
        }
Пример #2
0
        public ContainerRegistry(IObjectProvider objectProvider, GeckoContainer geckoContainer, BaseContext context = null)
        {
            ObjectProvider  = objectProvider;
            _geckoContainer = geckoContainer;
            Context         = context;

            TryAddRegistryToContext();
        }
Пример #3
0
        public void ConstructorParameterInjection()
        {
            var container = new ShandyGecko.ShandyGeckoDI.GeckoContainer();
            var test1     = new Test1();
            var test2     = container.BuildUpType <Test2>(new Parameter(test1));

            Assert.NotNull(test2);
            Assert.AreEqual(test1, test2.Test1);
        }
Пример #4
0
        public object GetObject(GeckoContainer geckoContainer, params Parameter[] parameters)
        {
            if (_factoryMethod == null)
            {
                return(geckoContainer.BuildUpType <T>(parameters));
            }

            var createdObj = _factoryMethod();

            return(geckoContainer.BuildUp(createdObj, parameters));
        }
Пример #5
0
        public void ContextDisposeText()
        {
            var container = new ShandyGecko.ShandyGeckoDI.GeckoContainer();
            var context   = new ShandyGecko.ShandyGeckoDI.Context();

            container.RegisterInstance(new TestClass(), context);
            Assert.AreEqual(1, context.ContainerRegistries.Count);

            context.Dispose();
            Assert.AreEqual(0, context.ContainerRegistries.Count);
            Assert.IsFalse(container.IsKeyRegistered <TestClass>());
        }
Пример #6
0
        public object GetObject(GeckoContainer geckoContainer, params Parameter[] parameters)
        {
            if (_isCreated)
            {
                return(_instance);
            }

            _instance  = geckoContainer.BuildUpType <T>(parameters);
            _isCreated = true;

            return(_instance);
        }
Пример #7
0
        public object GetObject(GeckoContainer geckoContainer, params Parameter[] parameters)
        {
            if (!IsDestroyed())
            {
                return(_instance);
            }

            _instance = FindObject();

            // TODO возможно понадобится BuildUp компонентов не-GeckoBehaviour
            if (!(_instance is GeckoBehaviour geckoBehaviour))
            {
                return(_instance);
            }

            if (!geckoBehaviour.BuiltUp)
            {
                geckoBehaviour.BuildUp(parameters);
            }

            return(_instance);
        }
Пример #8
0
 public static ContainerRegistry RegisterSceneObject <T>(this GeckoContainer geckoContainer, string path, BaseContext context = null) where T : Object
 {
     return(geckoContainer.RegisterProvider <T>(new FindObjectByPathProvider <T>(path), context));
 }
Пример #9
0
 public static ContainerRegistry RegisterUnityObject <T>(this GeckoContainer geckoContainer, BaseContext context = null) where T : Object
 {
     return(geckoContainer.RegisterProvider <T>(new FindObjectProvider <T>(), context));
 }
Пример #10
0
 public object GetObject(GeckoContainer geckoContainer, params Parameter[] parameters)
 {
     return(_instance);
 }