Exemple #1
0
        public object GetObject(CryoContainer container, params object[] parameters)
        {
            var obj = _factoryMethod();

            container.BuildUp(obj, parameters);

            LifeTimeManager.TryToAdd(obj, LifeTime);
            return(obj);
        }
Exemple #2
0
        public object GetObject(CryoContainer container, params object[] parameters)
        {
            if (!_exist)
            {
                _instance = _factoryMethod();
                _exist    = true;

                container.BuildUp(_instance, parameters);
                LifeTimeManager.TryToAdd(this, LifeTime);
            }
            return(_instance);
        }
Exemple #3
0
        public object GetObject(object owner, CryoContainer container, params object[] parameters)
        {
            var obj = _factoryMethod();

            container.BuildUp(obj, parameters);

            if (obj is IDisposable disposable)
            {
                _lifeTimeManager.Add(disposable, LifeTime);
            }
            return(obj);
        }
Exemple #4
0
        public void TestBuildUpSimilarParams()
        {
            var container = new CryoContainer();

            var val = new ClassWithSimilarParams();

            container.BuildUp(val, new Param {
                Name = "Two", Value = 2
            }, "Hello, world!", new Param("One", 1));
            Assert.AreEqual(1, val.One);
            Assert.AreEqual(2, val.Two);
            Assert.AreEqual("Hello, world!", val.Str);
        }
        public void TestSimplePropertiesBuildup()
        {
            var container = new CryoContainer();

            container.RegisterInstance("private base", "PrivateBase");
            container.RegisterInstance("protected base", "ProtectedBase");
            container.RegisterInstance("public base", "PublicBase");

            var a = new ClassBase();

            container.BuildUp(a);
            a.Check();
        }
Exemple #6
0
        public void TestBuildUpFailed()
        {
            var container = new CryoContainer();

            try
            {
                var val = new ClassWithParams();
                container.BuildUp(val);
                Assert.Fail("Expected exception not happened");
            }
            catch (ContainerException)
            {
            }
        }
Exemple #7
0
        public void TestBuildUpSimilarParamsFailed2()
        {
            var container = new CryoContainer();

            var val = new ClassWithSimilarParams();

            try
            {
                container.BuildUp(val, 1, "Hello, world!", 2);
                Assert.Fail("Expected exception not happened");
            }
            catch (ContainerException)
            {
            }
        }
Exemple #8
0
        public void TestBuildUp()
        {
            var container = new CryoContainer();

            var now    = DateTime.Now;
            var stream = new MemoryStream();

            var val = new ClassWithParams();

            container.BuildUp(val, stream, now, 3, 1.12f);

            Assert.AreEqual(now, val.DateTimeParam);
            Assert.AreEqual(stream, val.DisposableParam);
            Assert.AreEqual(3, val.IntParam);
            Assert.AreEqual(1.12f, val.FloatParam, 0.000001);
        }
        public void TestDerivedPropertiesBuildup()
        {
            var container = new CryoContainer();

            container.RegisterInstance("private base", "PrivateBase");
            container.RegisterInstance("protected base", "ProtectedBase");
            container.RegisterInstance("public base", "PublicBase");

            container.RegisterInstance("private derived", "PrivateDerived");
            container.RegisterInstance("protected derived", "ProtectedDerived");
            container.RegisterInstance("public derived", "PublicDerived");

            var a = new ClassDerived();

            container.BuildUp(a);
            a.Check();
        }
        public object GetObject(object owner, CryoContainer container, params object[] parameters)
        {
            if (!_exist)
            {
                UnityEngine.Object prefab = Resources.Load("Singletons/" + typeof(T).Name);

                var instance = UnityEngine.Object.Instantiate(prefab) as GameObject;
                instance.name = typeof(T).ToString();

                _instance = instance.GetComponent(typeof(T)) as T;
                _exist    = true;

                container.BuildUp(_instance, parameters);
                _lifeTimeManager.Add(this, LifeTime);

                UnityEngine.Object.DontDestroyOnLoad(_instance);
            }

            return(_instance);
        }
Exemple #11
0
 public void BuildUp(T obj, params object[] parameters)
 {
     _container.BuildUp(obj, parameters);
 }
Exemple #12
0
 public T BuildUp(T obj, params object[] parameters)
 {
     _container.BuildUp(obj, parameters);
     return(obj);
 }