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); }
public void IgnoresUnresolvableVariable() { StaticApplicationContext ac = new StaticApplicationContext(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("name", "${name}"); pvs.Add("nickname", "${nickname}"); ac.RegisterSingleton("tb1", typeof(TestObject), pvs); VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer(); vpc.IgnoreUnresolvablePlaceholders = true; vpc.VariableSource = new DictionaryVariableSource(new string[] { "name", "Erich" }); ac.AddObjectFactoryPostProcessor(vpc); ac.Refresh(); TestObject tb1 = (TestObject)ac.GetObject("tb1"); Assert.AreEqual("Erich", tb1.Name); Assert.AreEqual("${nickname}", tb1.Nickname); }