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 _Setup() { ObjectFactory = new DefaultListableObjectFactory(true); invocationLog.Clear(); _parentCounter = 0; _childCounter = 0; }
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 AddObjectFactoryOnObjectFactoryAwareObjectPostProcessors() { AbstractObjectFactory aof = ObjectFactory; LifecycleObject.PostProcessor lb = new LifecycleObject.PostProcessor(); aof.AddObjectPostProcessor(lb); Assert.AreSame(aof, lb.ObjectFactory); }
/// <summary> /// Initializes a new instance of the <see cref="ConstructorResolver"/> class for the given factory /// and instantiation strategy. /// </summary> /// <param name="objectFactory">The object factory to work with.</param> /// <param name="autowireFactory">The object factory as IAutowireCapableObjectFactory.</param> /// <param name="instantiationStrategy">The instantiation strategy for creating objects.</param> /// <param name="valueResolver">the resolver to resolve property value placeholders if any</param> public ConstructorResolver(AbstractObjectFactory objectFactory, IAutowireCapableObjectFactory autowireFactory, IInstantiationStrategy instantiationStrategy, ObjectDefinitionValueResolver valueResolver) { this.objectFactory = objectFactory; this.autowireFactory = autowireFactory; this.instantiationStrategy = instantiationStrategy; this.valueResolver = valueResolver; }
/// <summary> /// Create a new instance of the RemoteFactory. /// </summary> public CaoRemoteFactory(ILifetime lifetime, string targetName, string[] interfaces, AbstractObjectFactory objectFactory) { this.targetName = targetName; this.objectFactory = objectFactory; this.remoteObjectFactory = new RemoteObjectFactory(); this.remoteObjectFactory.BaseType = typeof(BaseCao); this.remoteObjectFactory.Interfaces = interfaces; this.remoteObjectFactory.Infinite = lifetime.Infinite; this.remoteObjectFactory.InitialLeaseTime = lifetime.InitialLeaseTime; this.remoteObjectFactory.RenewOnCallTime = lifetime.RenewOnCallTime; this.remoteObjectFactory.SponsorshipTimeout = lifetime.SponsorshipTimeout; }
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); }
public void CanDisposeFactoryWhenDependentObjectCallsFactoryInDispose() { AbstractObjectFactory factory = CreateObjectFactory(false); ConfigureObjectFactory(factory as IObjectDefinitionRegistry); ParentClass parent = (ParentClass)factory.GetObject("Parent"); Assert.That(parent, Is.Not.Null); DisposableClass innerObject = (DisposableClass)parent.InnerObject; innerObject.ObjectFactory = factory; factory.Dispose(); Assert.Pass("Test concluded successfully."); }
public void RespectsCaseInsensitiveNamesAndAliases() { AbstractObjectFactory of = CreateObjectFactory(false); object testObject = new object(); of.RegisterSingleton("name", testObject); of.RegisterAlias("NAME", "alias"); try { of.RegisterAlias("NaMe", "AlIaS"); Assert.Fail(); } catch (ObjectDefinitionStoreException ex) { Assert.IsTrue(-1 < ex.Message.IndexOf("already registered")); } Assert.AreEqual(1, of.GetAliases("nAmE").Length); Assert.AreEqual(testObject, of.GetObject("nAmE")); Assert.AreEqual(testObject, of.GetObject("ALIAS")); }
/// <summary> /// Initializes a new instance of the <see cref="ObjectDefinitionValueResolver"/> class. /// </summary> /// <param name="objectFactory">The object factory.</param> public ObjectDefinitionValueResolver(AbstractObjectFactory objectFactory) { this.log = LogManager.GetLogger(this.GetType()); this.objectFactory = objectFactory; }
/// <summary> /// Initializes a new instance of the <see cref="ObjectDefinitionValueResolver"/> class. /// </summary> /// <param name="objectFactory">The object factory.</param> public ObjectDefinitionValueResolver(AbstractObjectFactory objectFactory) { log = LogManager.GetLogger <ObjectDefinitionValueResolver>(); this.objectFactory = objectFactory; }