本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.PreInstantiateSingletons方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory.PreInstantiateSingletons方法的具体用法?C# DefaultListableObjectFactory.PreInstantiateSingletons怎么用?C# DefaultListableObjectFactory.PreInstantiateSingletons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Support.DefaultListableObjectFactory
的用法示例。
在下文中一共展示了DefaultListableObjectFactory.PreInstantiateSingletons方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtensiveCircularReference
public void ExtensiveCircularReference()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
for (int i = 0; i < 1000; i++)
{
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add(new PropertyValue("Spouse", new RuntimeObjectReference("object" + (i < 99 ? i + 1 : 0))));
RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
lof.RegisterObjectDefinition("object" + i, rod);
}
lof.PreInstantiateSingletons();
for (int i = 0; i < 1000; i++)
{
TestObject obj = (TestObject)lof.GetObject("object" + i);
TestObject otherObj = (TestObject)lof.GetObject("object" + (i < 99 ? i + 1 : 0));
Assert.IsTrue(obj.Spouse == otherObj);
}
}
示例2: SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall
public void SingletonFactoryObjectMustNotCreatePrototypeOnPreInstantiateSingletonsCall()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition def = new RootObjectDefinition();
def.ObjectType = typeof(DummyFactory);
def.IsSingleton = true;
def.PropertyValues.Add("IsSingleton", false);
DummyFactory.Reset();
Assert.IsFalse(DummyFactory.WasPrototypeCreated,
"Prototype appears to be instantiated before the test is even run.");
lof.RegisterObjectDefinition("x1", def);
Assert.IsFalse(DummyFactory.WasPrototypeCreated,
"Prototype instantiated after object definition registration (must NOT be).");
lof.PreInstantiateSingletons();
Assert.IsFalse(DummyFactory.WasPrototypeCreated,
"Prototype instantiated after call to PreInstantiateSingletons(); must NOT be.");
lof.GetObject("x1");
Assert.IsTrue(DummyFactory.WasPrototypeCreated, "Prototype was not instantiated.");
}
示例3: PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes
public void PreInstantiateSingletonsMustNotIgnoreObjectsWithUnresolvedObjectTypes()
{
KnowsIfInstantiated.ClearInstantiationRecord();
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
RootObjectDefinition def = new RootObjectDefinition();
def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
lof.RegisterObjectDefinition("x1", def);
Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
lof.PreInstantiateSingletons();
Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
}
示例4: LazyInitialization
public void LazyInitialization()
{
KnowsIfInstantiated.ClearInstantiationRecord();
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition def = new RootObjectDefinition();
def.ObjectTypeName = typeof(KnowsIfInstantiated).FullName;
def.IsLazyInit = true;
lof.RegisterObjectDefinition("x1", def);
Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before the test is even run.");
lof.RegisterObjectDefinition("x1", def);
Assert.IsTrue(!KnowsIfInstantiated.WasInstantiated, "Singleton appears to be instantiated before PreInstantiateSingletons() is invoked.");
lof.PreInstantiateSingletons();
Assert.IsFalse(KnowsIfInstantiated.WasInstantiated, "Singleton was instantiated by the container (it must NOT be 'cos LazyInit was set to TRUE).");
lof.GetObject("x1");
Assert.IsTrue(KnowsIfInstantiated.WasInstantiated, "Singleton was not instantiated by the container (it must be).");
}
示例5: DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException
public void DisposeCyclesThroughAllSingletonsEvenIfTheirDisposeThrowsAnException()
{
RootObjectDefinition foo = new RootObjectDefinition(typeof(GoodDisposable));
foo.IsSingleton = true;
RootObjectDefinition bar = new RootObjectDefinition(typeof(BadDisposable));
bar.IsSingleton = true;
RootObjectDefinition baz = new RootObjectDefinition(typeof(GoodDisposable));
baz.IsSingleton = true;
using (DefaultListableObjectFactory fac = new DefaultListableObjectFactory())
{
fac.RegisterObjectDefinition("foo", foo);
fac.RegisterObjectDefinition("bar", bar);
fac.RegisterObjectDefinition("baz", baz);
fac.PreInstantiateSingletons();
}
Assert.AreEqual(2, GoodDisposable.DisposeCount, "All IDisposable singletons must have their Dispose() method called... one of them bailed, and as a result the rest were (apparently) not Dispose()d.");
GoodDisposable.DisposeCount = 0;
}