public void GetObjectIsThreadSafe() { ObjectFactory = CreateObjectFactory(true); GenericObjectDefinition theSpouse = new GenericObjectDefinition(); theSpouse.ObjectTypeName = typeof(TestObject).FullName; theSpouse.IsSingleton = false; ObjectFactory.RegisterObjectDefinition("theSpouse", theSpouse); GenericObjectDefinition theObject = new GenericObjectDefinition(); theObject.ObjectTypeName = typeof(TestObject).FullName; theObject.IsSingleton = false; theObject.PropertyValues.Add("Spouse", theSpouse); ObjectFactory.RegisterObjectDefinition("theObject", theObject); AsyncTestTask t1 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t2 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t3 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); AsyncTestTask t4 = new AsyncTestMethod(20000, new ThreadStart(GetTheTestObject)).Start(); t1.AssertNoException(); t2.AssertNoException(); t3.AssertNoException(); t4.AssertNoException(); }
public void CanResolveCyclicSingletonFactoryObjectProductDependencies() { AbstractObjectFactory of = this.CreateObjectFactory(true); GenericObjectDefinition od = new GenericObjectDefinition(); od.ObjectTypeName = typeof(TestObject).FullName; od.IsSingleton = true; od.PropertyValues.Add(new PropertyValue("Spouse", new RuntimeObjectReference("product2"))); of.RegisterObjectDefinition("product1Target", od); GenericObjectDefinition od2 = new GenericObjectDefinition(); od2.ObjectTypeName = typeof(TestObject).FullName; od2.IsSingleton = true; od2.PropertyValues.Add(new PropertyValue("Sibling", new RuntimeObjectReference("product1"))); of.RegisterObjectDefinition("product2Target", od2); of.RegisterSingleton("product1", new ObjectReferenceFactoryObject("product1Target", of)); of.RegisterSingleton("product2", new ObjectReferenceFactoryObject("product2Target", of)); TestObject to = (TestObject)of.GetObject("product1"); Assert.NotNull(to); Assert.NotNull(to.Spouse); Assert.NotNull(((TestObject)to.Spouse).Sibling); }
public void ThrowsOnCyclicDependenciesOnNonSingletons() { AbstractObjectFactory of = this.CreateObjectFactory(true); GenericObjectDefinition od = new GenericObjectDefinition(); od.ObjectTypeName = typeof(TestObject).FullName; od.IsSingleton = false; od.PropertyValues.Add(new PropertyValue("Spouse", new RuntimeObjectReference("product2"))); of.RegisterObjectDefinition("product1", od); GenericObjectDefinition od2 = new GenericObjectDefinition(); od2.ObjectTypeName = typeof(TestObject).FullName; od2.IsSingleton = false; od2.PropertyValues.Add(new PropertyValue("Sibling", new RuntimeObjectReference("product1"))); of.RegisterObjectDefinition("product2", od2); try { of.GetObject("product1"); Assert.Fail(); } catch (ObjectCurrentlyInCreationException ex) { Assert.AreEqual("product1", ex.ObjectName); } }
public void _SetUp() { ObjectFactory = CreateObjectFactory(true); GenericObjectDefinition threadCreatorInsideConstructor = new GenericObjectDefinition(); threadCreatorInsideConstructor.ObjectTypeName = typeof(ThreadCreatorInsideConstructor).FullName; threadCreatorInsideConstructor.IsSingleton = true; ObjectFactory.RegisterObjectDefinition("threadCreatorInsideConstructor", threadCreatorInsideConstructor); GenericObjectDefinition threadCreatorInsideDispose = new GenericObjectDefinition(); threadCreatorInsideDispose.ObjectTypeName = typeof(ThreadCreatorInsideDispose).FullName; threadCreatorInsideDispose.IsSingleton = true; ObjectFactory.RegisterObjectDefinition("threadCreatorInsideDispose", threadCreatorInsideDispose); }