public void CanBindAndGetPrototype() { TestStruct testStruct; testStruct.idx = 8; testStruct.value = 99; const string defaultKey = "default"; IoCObjectContainer iocCon = new IoCObjectContainer(); iocCon.Bind(new TestEmptyClass(), defaultKey); iocCon.Bind(new TestClassWithConstructor((TestEmptyClass)iocCon.Get(typeof(TestEmptyClass), defaultKey)), defaultKey); iocCon.Bind(testStruct, InstantiationType.PROTOTYPE, defaultKey); TestClassWithConstructor testObj1 = (TestClassWithConstructor)iocCon.Get(typeof(TestClassWithConstructor), defaultKey); TestClassWithConstructor testObj2 = (TestClassWithConstructor)iocCon.Get(typeof(TestClassWithConstructor), defaultKey); Assert.AreNotSame(testObj1, testObj2); Assert.AreSame(testObj1.TestEmptyCls, testObj2.TestEmptyCls); TestStruct testStruct1 = (TestStruct)iocCon.Get(typeof(TestStruct), defaultKey); TestStruct testStruct2 = (TestStruct)iocCon.Get(typeof(TestStruct), defaultKey); Assert.AreNotSame(testStruct, testStruct1); Assert.AreNotSame(testStruct, testStruct2); Assert.AreNotSame(testStruct1, testStruct2); Assert.AreEqual(testStruct, testStruct1); Assert.AreEqual(testStruct, testStruct2); }
public void CanNewInstance() { TestClassWithConstructor objWithDefaultSingleton = StaticContainer.NewInstance <TestClassWithConstructor>(); Assert.IsNotNull(objWithDefaultSingleton); Assert.AreSame(DEFAULT_EMPTY_CLASS, objWithDefaultSingleton.TestEmptyCls); TestClassWithCustomConstructor objWithCustomSingleton = StaticContainer.NewInstance <TestClassWithCustomConstructor>(); Assert.IsNotNull(objWithCustomSingleton); Assert.AreSame(CUSTOM_EMPTY_CLASS, objWithCustomSingleton.TestEmptyCls); }