本文整理汇总了C#中Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectDefinition方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultListableObjectFactory.GetObjectDefinition方法的具体用法?C# DefaultListableObjectFactory.GetObjectDefinition怎么用?C# DefaultListableObjectFactory.GetObjectDefinition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Objects.Factory.Support.DefaultListableObjectFactory
的用法示例。
在下文中一共展示了DefaultListableObjectFactory.GetObjectDefinition方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetObjectDefinitionResolvesAliases
public void GetObjectDefinitionResolvesAliases()
{
const string TheParentsAlias = "theParentsAlias";
const int ExpectedAge = 31;
const string ExpectedName = "Rick Evans";
RootObjectDefinition parentDef = new RootObjectDefinition(typeof(TestObject));
parentDef.IsAbstract = true;
parentDef.PropertyValues.Add("name", ExpectedName);
parentDef.PropertyValues.Add("age", ExpectedAge);
ChildObjectDefinition childDef = new ChildObjectDefinition(TheParentsAlias);
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
fac.RegisterObjectDefinition("parent", parentDef);
fac.RegisterAlias("parent", TheParentsAlias);
IObjectDefinition od = fac.GetObjectDefinition(TheParentsAlias);
Assert.IsNotNull(od);
}
示例2: ParsesObjectAttributes
public void ParsesObjectAttributes()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net'>
<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='false' abstract='true' />
<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' singleton='true' abstract='false' lazy-init='true'
autowire='no' dependency-check='simple'
depends-on='test1'
init-method='init'
destroy-method='destroy'
/>
</objects>
"));
AbstractObjectDefinition od1 = (AbstractObjectDefinition)of.GetObjectDefinition("test1");
Assert.IsFalse(od1.IsSingleton);
Assert.IsTrue(od1.IsAbstract);
Assert.IsFalse(od1.IsLazyInit);
AbstractObjectDefinition od2 = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
Assert.IsTrue(od2.IsSingleton);
Assert.IsFalse(od2.IsAbstract);
Assert.IsTrue(od2.IsLazyInit);
Assert.AreEqual(AutoWiringMode.No, od2.AutowireMode);
Assert.AreEqual("init", od2.InitMethodName);
Assert.AreEqual("destroy", od2.DestroyMethodName);
Assert.AreEqual(1, od2.DependsOn.Length);
Assert.AreEqual("test1", od2.DependsOn[0]);
Assert.AreEqual(DependencyCheckingMode.Simple, od2.DependencyCheck);
}
示例3: ChainedResolutionWithNullValues
public void ChainedResolutionWithNullValues()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("NameProperty", "${name}");
pvs.Add("NickNameProperty", "${nickname}");
of.RegisterObjectDefinition("tb1", new RootObjectDefinition("typename", null, pvs));
IList variableSources = new ArrayList();
variableSources.Add(new DictionaryVariableSource(new string[] { "name", "name-value", "nickname", null }));
variableSources.Add(new DictionaryVariableSource(new string[] { "nickname", "nickname-value" }));
VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);
vphc.PostProcessObjectFactory(of);
RootObjectDefinition rod = (RootObjectDefinition)of.GetObjectDefinition("tb1");
Assert.AreEqual("name-value", rod.PropertyValues.GetPropertyValue("NameProperty").Value);
Assert.AreEqual(null, rod.PropertyValues.GetPropertyValue("NickNameProperty").Value);
}
示例4: ParsesAutowireCandidate
public void ParsesAutowireCandidate()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
XmlObjectDefinitionReader reader = new XmlObjectDefinitionReader(of);
reader.LoadObjectDefinitions(new StringResource(
@"<?xml version='1.0' encoding='UTF-8' ?>
<objects xmlns='http://www.springframework.net' default-autowire-candidates='test1*,test4*'>
<object id='test1' type='Spring.Objects.TestObject, Spring.Core.Tests' />
<object id='test2' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='false' />
<object id='test3' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='true' />
<object id='test4' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
<object id='test5' type='Spring.Objects.TestObject, Spring.Core.Tests' autowire-candidate='default' />
</objects>
"));
var od = (AbstractObjectDefinition)of.GetObjectDefinition("test1");
Assert.That(od.IsAutowireCandidate, Is.True, "No attribute set should default to true");
od = (AbstractObjectDefinition)of.GetObjectDefinition("test2");
Assert.That(od.IsAutowireCandidate, Is.False, "Specifically attribute set to false should set to false");
od = (AbstractObjectDefinition)of.GetObjectDefinition("test3");
Assert.That(od.IsAutowireCandidate, Is.True, "Specifically attribute set to true should set to false");
od = (AbstractObjectDefinition)of.GetObjectDefinition("test4");
Assert.That(od.IsAutowireCandidate, Is.True, "Attribute set to default should check pattern and return true");
od = (AbstractObjectDefinition)of.GetObjectDefinition("test5");
Assert.That(od.IsAutowireCandidate, Is.False, "Attribute set to default should check pattern and return false");
}
示例5: MultiResolution
public void MultiResolution()
{
DefaultListableObjectFactory of = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("Greeting", "Hello ${firstname} ${lastname}!");
of.RegisterObjectDefinition("tb1", new RootObjectDefinition("typename", null, pvs));
IList variableSources = new ArrayList();
variableSources.Add(new DictionaryVariableSource(new string[] { "firstname", "FirstName" }));
variableSources.Add(new DictionaryVariableSource(new string[] { "lastname", "LastName" }));
VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);
vphc.PostProcessObjectFactory(of);
RootObjectDefinition rod = (RootObjectDefinition)of.GetObjectDefinition("tb1");
Assert.AreEqual("Hello FirstName LastName!", rod.PropertyValues.GetPropertyValue("Greeting").Value);
}