本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObject方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory.GetObject方法的具体用法?C# DefaultListableObjectFactory.GetObject怎么用?C# DefaultListableObjectFactory.GetObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Support.DefaultListableObjectFactory
的用法示例。
在下文中一共展示了DefaultListableObjectFactory.GetObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_Create_Custom_Scan_Routine
public void Can_Create_Custom_Scan_Routine()
{
var scanner = new ScanOverridingAssemblyObjectDefinitionScanner();
var registry = new DefaultListableObjectFactory();
scanner.ScanAndRegisterTypes(registry);
Assert.That(registry.ObjectDefinitionCount, Is.EqualTo(1), "found multiple definitions");
Assert.That(registry.GetObject<ComponentScan.ScanComponentsAndAddToContext.ConfigurationImpl>(), Is.Not.Null,
"correct single defintion was not registered");
}
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:9,代码来源:AssemblyObjectDefinitionScannerTests.cs
示例2: ShouldAllowConfigurationClassInheritance
public void ShouldAllowConfigurationClassInheritance()
{
var factory = new DefaultListableObjectFactory();
factory.RegisterObjectDefinition("DerivedConfiguration", new GenericObjectDefinition
{
ObjectType = typeof(DerivedConfiguration)
});
var processor = new ConfigurationClassPostProcessor();
processor.PostProcessObjectFactory(factory);
// we should get singleton instances only
TestObject testObject = (TestObject) factory.GetObject("DerivedDefinition");
string singletonParent = (string) factory.GetObject("BaseDefinition");
Assert.That(testObject.Value, Is.SameAs(singletonParent));
}
开发者ID:spring-projects,项目名称:spring-net-codeconfig,代码行数:18,代码来源:ConfigurationClassPostProcessorTests.cs
示例3: AddPersistenceExceptionTranslation
protected override void AddPersistenceExceptionTranslation(ProxyFactory pf, IPersistenceExceptionTranslator pet)
{
if (AttributeUtils.FindAttribute(pf.TargetType, typeof(RepositoryAttribute)) != null)
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
of.RegisterObjectDefinition("peti", new RootObjectDefinition(typeof(PersistenceExceptionTranslationInterceptor)));
of.RegisterSingleton("pet", pet);
pf.AddAdvice((PersistenceExceptionTranslationInterceptor) of.GetObject("peti"));
}
}
示例4: ProxyObjectWithoutInterface
public void ProxyObjectWithoutInterface()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
of.RegisterObjectDefinition("bar", new RootObjectDefinition(typeof(ObjectWithoutInterface)));
TestAutoProxyCreator apc = new TestAutoProxyCreator(of);
of.AddObjectPostProcessor(apc);
ObjectWithoutInterface o = of.GetObject("bar") as ObjectWithoutInterface;
Assert.IsTrue(AopUtils.IsAopProxy(o));
o.Foo();
Assert.AreEqual(1, apc.NopInterceptor.Count);
}
示例5: ConvertsWriteConcernCorrectly
public void ConvertsWriteConcernCorrectly()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
factory.RegisterCustomConverter(typeof(WriteConcern), new WriteConcernTypeConverter());
RootObjectDefinition definition = new RootObjectDefinition(typeof(MongoFactoryObject));
definition.PropertyValues.Add("Url", "mongodb://localhost");
definition.PropertyValues.Add("WriteConcern", "Acknowledged");
factory.RegisterObjectDefinition("factory", definition);
MongoFactoryObject obj = factory.GetObject<MongoFactoryObject>("&factory");
Assert.That(ReflectionUtils.GetInstanceFieldValue(obj, "_writeConcern"),
Is.EqualTo(WriteConcern.Acknowledged));
}
示例6: Test
public void Test()
{
int numIterations = 10000;
start = DateTime.Now;
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
InitFactory(factory);
for (int i = 0; i < numIterations; i++)
{
FFoo foo = (FFoo)factory.GetObject("foo");
}
stop = DateTime.Now;
double timeElapsed = Elapsed;
PrintTest("Creations", numIterations, timeElapsed);
}
示例7: CircularReferences
public void CircularReferences()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
TestObject jenny = (TestObject) xof.GetObject("jenny");
TestObject david = (TestObject) xof.GetObject("david");
TestObject ego = (TestObject) xof.GetObject("ego");
Assert.IsTrue(jenny.Spouse == david, "Correct circular reference");
Assert.IsTrue(david.Spouse == jenny, "Correct circular reference");
Assert.IsTrue(ego.Spouse == ego, "Correct circular reference");
}
示例8: InnerObjects
public void InnerObjects()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
// Let's create the outer bean named "innerObject",
// to check whether it doesn't create any conflicts
// with the actual inner object named "innerObject".
xof.GetObject("innerObject");
TestObject hasInnerObjects = (TestObject) xof.GetObject("hasInnerObjects");
Assert.AreEqual(5, hasInnerObjects.Age);
TestObject inner1 = (TestObject) hasInnerObjects.Spouse;
Assert.IsNotNull(inner1);
Assert.AreEqual("Spring.Objects.TestObject#", inner1.ObjectName.Substring(0, inner1.ObjectName.IndexOf("#")+1));
Assert.AreEqual("inner1", inner1.Name);
Assert.AreEqual(6, inner1.Age);
Assert.IsNotNull(hasInnerObjects.Friends);
IList friends = (IList) hasInnerObjects.Friends;
Assert.AreEqual(2, friends.Count);
DerivedTestObject inner2 = (DerivedTestObject) friends[0];
Assert.AreEqual("inner2", inner2.Name);
Assert.AreEqual(7, inner2.Age);
Assert.AreEqual("Spring.Objects.DerivedTestObject#", inner2.ObjectName.Substring(0, inner2.ObjectName.IndexOf("#") + 1));
TestObject innerFactory = (TestObject) friends[1];
Assert.AreEqual(DummyFactory.SINGLETON_NAME, innerFactory.Name);
Assert.IsNotNull(hasInnerObjects.SomeMap);
Assert.IsFalse((hasInnerObjects.SomeMap.Count == 0));
TestObject inner3 = (TestObject) hasInnerObjects.SomeMap["someKey"];
Assert.AreEqual("Jenny", inner3.Name);
Assert.AreEqual(30, inner3.Age);
xof.Dispose();
Assert.IsTrue(inner2.WasDestroyed());
Assert.IsTrue(innerFactory.Name == null);
}
示例9: RefToSeparatePrototypeInstances
public void RefToSeparatePrototypeInstances()
{
DefaultListableObjectFactory xof = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(xof);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("reftypes.xml", GetType()));
Assert.IsTrue(xof.ObjectDefinitionCount == 9, "9 objects in reftypes, not " + xof.ObjectDefinitionCount);
TestObject emma = (TestObject) xof.GetObject("emma");
TestObject georgia = (TestObject) xof.GetObject("georgia");
ITestObject emmasJenks = emma.Spouse;
ITestObject georgiasJenks = georgia.Spouse;
Assert.IsTrue(emmasJenks != georgiasJenks, "Emma and georgia think they have a different boyfriend.");
Assert.IsTrue(emmasJenks.Name.Equals("Andrew"), "Emmas jenks has right name");
Assert.IsTrue(emmasJenks != xof.GetObject("jenks"), "Emmas doesn't equal new ref.");
Assert.IsTrue(emmasJenks.Name.Equals("Andrew"), "Georgias jenks has right name.");
Assert.IsTrue(emmasJenks.Equals(georgiasJenks), "They are object equal.");
Assert.IsTrue(emmasJenks.Equals(xof.GetObject("jenks")), "They object equal direct ref.");
}
示例10: BailsOnRubbishPropertyRetrievingFactoryMethod
public void BailsOnRubbishPropertyRetrievingFactoryMethod()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("field-props-factory.xml", GetType()));
factory.GetObject("rubbishProperty", typeof(MyTestObject));
}
示例11: StaticFieldRetrievingFactoryMethod
public void StaticFieldRetrievingFactoryMethod()
{
DefaultListableObjectFactory factory = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(factory);
reader.LoadObjectDefinitions(new ReadOnlyXmlTestResource("field-props-factory.xml", GetType()));
MyTestObject obj = factory.GetObject("withTypesField", typeof(MyTestObject)) as MyTestObject;
Assert.IsNotNull(obj.Types);
Assert.AreEqual(Type.EmptyTypes.Length, obj.Types.Length);
}
示例12: AutowireWithSatisfiedConstructorDependency
public void AutowireWithSatisfiedConstructorDependency()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add(new PropertyValue("name", "Rod"));
RootObjectDefinition rood = new RootObjectDefinition(typeof(TestObject), pvs);
lof.RegisterObjectDefinition("rod", rood);
Assert.AreEqual(1, lof.ObjectDefinitionCount);
object registered = lof.Autowire(typeof(ConstructorDependency), AutoWiringMode.AutoDetect, false);
Assert.AreEqual(1, lof.ObjectDefinitionCount);
ConstructorDependency kerry = (ConstructorDependency)registered;
TestObject rod = (TestObject)lof.GetObject("rod");
Assert.AreSame(rod, kerry._spouse);
}
示例13: AutowireExistingObjectByType
public void AutowireExistingObjectByType()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
lof.RegisterObjectDefinition("test", rod);
DependenciesObject existingObj = new DependenciesObject();
lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByType, true);
TestObject test = (TestObject)lof.GetObject("test");
Assert.AreEqual(existingObj.Spouse, test);
}
示例14: AutowireExistingObjectByName
public void AutowireExistingObjectByName()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject));
lof.RegisterObjectDefinition("Spouse", rod);
DependenciesObject existingObj = new DependenciesObject();
lof.AutowireObjectProperties(existingObj, AutoWiringMode.ByName, true);
TestObject spouse = (TestObject)lof.GetObject("Spouse");
Assert.AreEqual(existingObj.Spouse, spouse);
Assert.IsTrue(ObjectFactoryUtils.ObjectOfType(lof, typeof(TestObject)) == spouse);
}
示例15: AutowireObjectByNameIsNotCaseInsensitive
public void AutowireObjectByNameIsNotCaseInsensitive()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
RootObjectDefinition rodDefinition = new RootObjectDefinition(typeof(TestObject));
rodDefinition.PropertyValues.Add("name", "Rod");
rodDefinition.AutowireMode = AutoWiringMode.ByName;
RootObjectDefinition kerryDefinition = new RootObjectDefinition(typeof(TestObject));
kerryDefinition.PropertyValues.Add("name", "Kerry");
lof.RegisterObjectDefinition("rod", rodDefinition);
lof.RegisterObjectDefinition("spouse", kerryDefinition); // property name is Spouse (capital S)
TestObject objRod = (TestObject)lof.GetObject("rod");
Assert.IsNull(objRod.Spouse, "Mmm, Spouse property appears to have been autowired by name, even though there is no object in the factory with a name 'Spouse'.");
}