本文整理汇总了C#中MutablePropertyValues类的典型用法代码示例。如果您正苦于以下问题:C# MutablePropertyValues类的具体用法?C# MutablePropertyValues怎么用?C# MutablePropertyValues使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MutablePropertyValues类属于命名空间,在下文中一共展示了MutablePropertyValues类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitFactory
private void InitFactory(DefaultListableObjectFactory factory)
{
Console.WriteLine("init factory");
RootObjectDefinition tee = new RootObjectDefinition(typeof(Tee), true);
tee.IsLazyInit = true;
ConstructorArgumentValues teeValues = new ConstructorArgumentValues();
teeValues.AddGenericArgumentValue("test");
tee.ConstructorArgumentValues = teeValues;
RootObjectDefinition bar = new RootObjectDefinition(typeof(BBar), false);
ConstructorArgumentValues barValues = new ConstructorArgumentValues();
barValues.AddGenericArgumentValue(new RuntimeObjectReference("tee"));
barValues.AddGenericArgumentValue(5);
bar.ConstructorArgumentValues = barValues;
RootObjectDefinition foo = new RootObjectDefinition(typeof(FFoo), false);
MutablePropertyValues fooValues = new MutablePropertyValues();
fooValues.Add("i", 5);
fooValues.Add("bar", new RuntimeObjectReference("bar"));
fooValues.Add("copy", new RuntimeObjectReference("bar"));
fooValues.Add("s", "test");
foo.PropertyValues = fooValues;
factory.RegisterObjectDefinition("foo", foo);
factory.RegisterObjectDefinition("bar", bar);
factory.RegisterObjectDefinition("tee", tee);
}
示例2: AbstractObjectDefinition
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Objects.Factory.Support.AbstractObjectDefinition"/>
/// class.
/// </summary>
/// <remarks>
/// <p>
/// This is an <see langword="abstract"/> class, and as such exposes no
/// public constructors.
/// </p>
/// </remarks>
protected AbstractObjectDefinition(ConstructorArgumentValues arguments, MutablePropertyValues properties)
{
constructorArgumentValues =
(arguments != null) ? arguments : new ConstructorArgumentValues();
propertyValues =
(properties != null) ? properties : new MutablePropertyValues();
eventHandlerValues = new EventValues();
DependsOn = StringUtils.EmptyStrings;
}
示例3: ChainedResolution
public void ChainedResolution()
{
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("name", "${name}");
pvs.Add("nickname", "${nickname}");
ac.RegisterSingleton("tb1", typeof(TestObject), pvs);
IList variableSources = new ArrayList();
variableSources.Add(new DictionaryVariableSource(new string[] { "name", "name-value" }));
variableSources.Add(new DictionaryVariableSource(new string[] { "nickname", "nickname-value" }));
VariablePlaceholderConfigurer vphc = new VariablePlaceholderConfigurer(variableSources);
ac.AddObjectFactoryPostProcessor(vphc);
ac.Refresh();
TestObject tb1 = (TestObject)ac.GetObject("tb1");
Assert.AreEqual("name-value", tb1.Name);
Assert.AreEqual("nickname-value", tb1.Nickname);
}
示例4: AddPropertyValue
public void AddPropertyValue()
{
StaticApplicationContext ac = new StaticApplicationContext();
ac.RegisterSingleton("tb1", typeof(TestObject), new MutablePropertyValues());
ac.RegisterSingleton("tb2", typeof(TestObject), new MutablePropertyValues());
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("Properties", "<spring-config><add key=\"tb1.Age\" value=\"99\"/><add key=\"tb2.Name\" value=\"test\"/></spring-config>");
ac.RegisterSingleton("configurer1", typeof(PropertyOverrideConfigurer), pvs);
pvs = new MutablePropertyValues();
pvs.Add("Properties", "<spring-config><add key=\"tb2.Age\" value=\"99\"/><add key=\"tb2.Name\" value=\"test\"/></spring-config>");
pvs.Add("order", "0");
ac.RegisterSingleton("configurer2", typeof(PropertyOverrideConfigurer), pvs);
ac.Refresh();
TestObject tb1 = (TestObject)ac.GetObject("tb1");
TestObject tb2 = (TestObject)ac.GetObject("tb2");
Assert.AreEqual(99, tb1.Age);
Assert.AreEqual(99, tb2.Age);
Assert.AreEqual(null, tb1.Name);
Assert.AreEqual("test", tb2.Name);
}
示例5: BailsOnUnresolvableVariable
public void BailsOnUnresolvableVariable()
{
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("nickname", "${nickname}");
ac.RegisterSingleton("tb1", typeof(TestObject), pvs);
IList variableSources = new ArrayList();
variableSources.Add(new DictionaryVariableSource(new string[] { }));
pvs = new MutablePropertyValues();
pvs.Add("VariableSources", variableSources);
ac.RegisterSingleton("configurer", typeof(VariablePlaceholderConfigurer), pvs);
try
{
ac.Refresh();
Assert.Fail("something changed wrt VariablePlaceholder resolution");
}
catch (ObjectDefinitionStoreException ex)
{
Assert.IsTrue(ex.Message.IndexOf("nickname") > -1);
}
}
示例6: 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);
}
示例7: AutowireWithUnsatisfiedConstructorDependency
public void AutowireWithUnsatisfiedConstructorDependency()
{
DefaultListableObjectFactory lof = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add(new PropertyValue("name", "Rod"));
RootObjectDefinition rod = new RootObjectDefinition(typeof(TestObject), pvs);
lof.RegisterObjectDefinition("rod", rod);
Assert.AreEqual(1, lof.ObjectDefinitionCount);
lof.Autowire(typeof(UnsatisfiedConstructorDependency), AutoWiringMode.AutoDetect, true);
Assert.Fail("Should have unsatisfied constructor dependency on SideEffectObject");
}
示例8: OverridePropertyExpression
public void OverridePropertyExpression()
{
StaticApplicationContext ac = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("Age", new ExpressionHolder("26+1"));
ac.RegisterSingleton("tb1", typeof(TestObject), pvs);
pvs = new MutablePropertyValues();
pvs.Add("Properties", "<spring-config><add key=\"tb1.Age\" value=\"26-1\"/></spring-config>");
ac.RegisterSingleton("configurer", typeof(PropertyOverrideConfigurer), pvs);
ac.Refresh();
TestObject tb1 = (TestObject)ac.GetObject("tb1");
Assert.AreEqual(25, tb1.Age);
}
示例9: ParsePropertyElements
/// <summary>
/// Parse property value subelements of the given object element.
/// </summary>
/// <param name="name">
/// The name of the object (definition) associated with the property element (s)
/// </param>
/// <param name="element">
/// The element containing the top level object definition.
/// </param>
/// <param name="parserContext">
/// The namespace-aware parser.
/// </param>
/// <returns>
/// The property (s) associated with the object (definition).
/// </returns>
protected virtual MutablePropertyValues ParsePropertyElements(
string name, XmlElement element, ParserContext parserContext)
{
MutablePropertyValues properties = new MutablePropertyValues();
foreach (XmlNode node in this.SelectNodes(element, ObjectDefinitionConstants.PropertyElement))
{
ParsePropertyElement(name, properties, (XmlElement)node, parserContext);
}
return properties;
}
示例10: RootWebObjectDefinition
/// <summary>
/// Creates a new instance of the
/// <see cref="Spring.Objects.Factory.Support.RootWebObjectDefinition"/> class
/// for an .aspx page, providing property values.
/// </summary>
/// <param name="pageName">
/// Name of the .aspx page to instantiate.
/// </param>
/// <param name="properties">
/// The <see cref="Spring.Objects.MutablePropertyValues"/> to be applied to
/// a new instance of the object.
/// </param>
public RootWebObjectDefinition(
string pageName,
MutablePropertyValues properties)
: base(WebObjectUtils.GetPageType(pageName), null, properties)
{
_pageName = WebUtils.CombineVirtualPaths(VirtualEnvironment.CurrentExecutionFilePath, pageName);
}
示例11: SPR_1077
public void SPR_1077()
{
DisposableTestObject sing = null;
using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
{
RootObjectDefinition singleton
= new RootObjectDefinition(typeof(DisposableTestObject));
MutablePropertyValues sprops = new MutablePropertyValues();
sprops.Add("name", "Rick");
singleton.PropertyValues = sprops;
lof.RegisterObjectDefinition("singleton", singleton);
RootObjectDefinition prototype
= new RootObjectDefinition(typeof(TestObject));
MutablePropertyValues pprops = new MutablePropertyValues();
pprops.Add("name", "Jenny");
// prototype has dependency on a singleton...
pprops.Add("spouse", new RuntimeObjectReference("singleton"));
prototype.PropertyValues = pprops;
prototype.IsSingleton = false;
lof.RegisterObjectDefinition("prototype", prototype);
sing = (DisposableTestObject)lof.GetObject("singleton");
lof.GetObject("prototype");
lof.GetObject("prototype");
lof.GetObject("prototype");
lof.GetObject("prototype");
}
Assert.AreEqual(1, sing.NumTimesDisposed);
}
示例12: AutowireWithParent
public void AutowireWithParent()
{
XmlObjectFactory xof = new XmlObjectFactory(new ReadOnlyXmlTestResource("autowire.xml", GetType()));
DefaultListableObjectFactory lbf = new DefaultListableObjectFactory();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.Add("Name", "kerry");
lbf.RegisterObjectDefinition("Spouse", new RootObjectDefinition(typeof(TestObject), pvs));
xof.ParentObjectFactory = lbf;
DoTestAutowire(xof);
}
示例13: CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments
public void CreateObjectWithMixOfNamedAndIndexedAndAutowiredCtorArguments()
{
string expectedCompany = "Griffin's Foosball Arcade";
MutablePropertyValues autoProps = new MutablePropertyValues();
autoProps.Add(new PropertyValue("Company", expectedCompany));
RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);
string expectedName = "Bingo";
int expectedAge = 1023;
ConstructorArgumentValues values = new ConstructorArgumentValues();
values.AddNamedArgumentValue("age", expectedAge);
values.AddIndexedArgumentValue(0, expectedName);
RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
def.AutowireMode = AutoWiringMode.Constructor;
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
fac.RegisterObjectDefinition("foo", def);
fac.RegisterObjectDefinition("doctor", autowired);
ITestObject foo = fac["foo"] as ITestObject;
Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
}
示例14: CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments
public void CreateObjectWithMixOfIndexedAndTwoNamedSameTypeCtorArguments()
{
// this object will be passed in as a named constructor argument
string expectedCompany = "Griffin's Foosball Arcade";
MutablePropertyValues autoProps = new MutablePropertyValues();
autoProps.Add(new PropertyValue("Company", expectedCompany));
RootObjectDefinition autowired = new RootObjectDefinition(typeof(NestedTestObject), autoProps);
// this object will be passed in as a named constructor argument
string expectedLawyersCompany = "Pollack, Pounce, & Pulverise";
MutablePropertyValues lawyerProps = new MutablePropertyValues();
lawyerProps.Add(new PropertyValue("Company", expectedLawyersCompany));
RootObjectDefinition lawyer = new RootObjectDefinition(typeof(NestedTestObject), lawyerProps);
// this simple string object will be passed in as an indexed constructor argument
string expectedName = "Bingo";
// this simple integer object will be passed in as a named constructor argument
int expectedAge = 1023;
ConstructorArgumentValues values = new ConstructorArgumentValues();
// lets mix the order up a little...
values.AddNamedArgumentValue("age", expectedAge);
values.AddIndexedArgumentValue(0, expectedName);
values.AddNamedArgumentValue("doctor", new RuntimeObjectReference("a_doctor"));
values.AddNamedArgumentValue("lawyer", new RuntimeObjectReference("a_lawyer"));
RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), values, new MutablePropertyValues());
DefaultListableObjectFactory fac = new DefaultListableObjectFactory();
// the object we're attempting to resolve...
fac.RegisterObjectDefinition("foo", def);
// the object that will be looked up and passed as a named parameter to a ctor call...
fac.RegisterObjectDefinition("a_doctor", autowired);
// another object that will be looked up and passed as a named parameter to a ctor call...
fac.RegisterObjectDefinition("a_lawyer", lawyer);
ITestObject foo = fac["foo"] as ITestObject;
Assert.IsNotNull(foo, "Couldn't pull manually registered instance out of the factory.");
Assert.AreEqual(expectedName, foo.Name, "Dependency 'name' was not resolved an indexed ctor arg.");
Assert.AreEqual(expectedAge, foo.Age, "Dependency 'age' was not resolved using a named ctor arg.");
Assert.AreEqual(expectedCompany, foo.Doctor.Company, "Dependency 'doctor.Company' was not resolved using autowiring.");
Assert.AreEqual(expectedLawyersCompany, foo.Lawyer.Company, "Dependency 'lawyer.Company' was not resolved using another named ctor arg.");
}
示例15: CreateObjectDoesAffectContainerManagedSingletons
public void CreateObjectDoesAffectContainerManagedSingletons()
{
using (DefaultListableObjectFactory lof = new DefaultListableObjectFactory())
{
lof.AddObjectPostProcessor(new SharedStateAwareProcessor(new ISharedStateFactory[] { new ByTypeSharedStateFactory() }, Int32.MaxValue ));
MutablePropertyValues properties = new MutablePropertyValues();
properties.Add(new PropertyValue("Age", 27));
properties.Add(new PropertyValue("Name", "Bruno"));
RootObjectDefinition singleton = new RootObjectDefinition(typeof(TestObject), null, properties);
singleton.IsSingleton = true;
lof.RegisterObjectDefinition("singleton", singleton);
// a call to GetObject() results in a normally configured instance
TestObject to = lof.GetObject("singleton") as TestObject;
Assert.IsNotNull(to);
// props set
Assert.AreEqual(27, to.Age);
Assert.AreEqual("Bruno", to.Name);
// object postprocessors executed!
Assert.AreEqual("singleton", to.ObjectName);
Assert.AreEqual(lof, to.ObjectFactory);
Assert.IsNotNull(to.SharedState);
// altough configured as singleton, calling CreateObject prevents the instance from being cached
// otherwise the container could not guarantee the results of calling GetObject() to other clients.
TestObject to2 = lof.CreateObject("singleton", typeof(TestObject), null) as TestObject;
Assert.IsNotNull(to2);
// no props set
Assert.AreEqual(0, to2.Age);
Assert.AreEqual(null, to2.Name);
// no object postprocessors executed!
Assert.AreEqual(null, to2.ObjectName);
Assert.AreEqual(null, to2.ObjectFactory);
Assert.AreEqual(null, to2.SharedState);
// a call to GetObject() results in a normally configured instance
TestObject to3 = lof.GetObject("singleton") as TestObject;
Assert.IsNotNull(to3);
// props set
Assert.AreEqual(27, to3.Age);
Assert.AreEqual("Bruno", to3.Name);
// object postprocessors executed!
Assert.AreEqual("singleton", to3.ObjectName);
Assert.AreEqual(lof, to3.ObjectFactory);
Assert.IsNotNull(to3.SharedState);
}
}