public object GetObject(CryoContainer container, params object[] parameters) { var obj = _factoryMethod(); container.BuildUp(obj, parameters); LifeTimeManager.TryToAdd(obj, LifeTime); return(obj); }
public object GetObject(CryoContainer container, params object[] parameters) { if (!_exist) { _instance = _factoryMethod(); _exist = true; container.BuildUp(_instance, parameters); LifeTimeManager.TryToAdd(this, LifeTime); } return(_instance); }
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); }
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(); }
public void TestBuildUpFailed() { var container = new CryoContainer(); try { var val = new ClassWithParams(); container.BuildUp(val); Assert.Fail("Expected exception not happened"); } catch (ContainerException) { } }
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) { } }
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); }
public void BuildUp(T obj, params object[] parameters) { _container.BuildUp(obj, parameters); }
public T BuildUp(T obj, params object[] parameters) { _container.BuildUp(obj, parameters); return(obj); }