From 88170e7974e6befe951976f0ebb95c7a22371d7a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 May 2013 10:28:37 -0600 Subject: [PATCH] SPRNET-1547 - ScannedGenericObjectDefinition doesn't apply default autowire mode --- .../Attributes/ScannedGenericObjectDefinition.cs | 14 ++++++++++++++ .../ComponentScanObjectDefinitionParserTests.cs | 9 +++++++++ .../Context/Config/ConfigFiles/ComponentScan5.xml | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Spring/Spring.Core/Context/Attributes/ScannedGenericObjectDefinition.cs b/src/Spring/Spring.Core/Context/Attributes/ScannedGenericObjectDefinition.cs index cdd5c80e..f5696c14 100644 --- a/src/Spring/Spring.Core/Context/Attributes/ScannedGenericObjectDefinition.cs +++ b/src/Spring/Spring.Core/Context/Attributes/ScannedGenericObjectDefinition.cs @@ -20,6 +20,7 @@ using System; using Spring.Objects; +using Spring.Objects.Factory.Config; using Spring.Objects.Factory.Support; using Spring.Objects.Factory.Xml; using Spring.Stereotype; @@ -71,8 +72,21 @@ namespace Spring.Context.Attributes bool lazyInit = false; bool.TryParse(defaults.LazyInit, out lazyInit); IsLazyInit = lazyInit; + + if (!String.IsNullOrEmpty(defaults.Autowire)) + { + AutowireMode = GetAutowireMode(defaults.Autowire); + } } + private AutoWiringMode GetAutowireMode(string value) + { + AutoWiringMode autoWiringMode; + autoWiringMode = (AutoWiringMode)Enum.Parse(typeof(AutoWiringMode), value, true); + return autoWiringMode; + } + + private void ParseScopeAttribute() { var attr = Attribute.GetCustomAttribute(ObjectType, typeof(ScopeAttribute), true) as ScopeAttribute; diff --git a/test/Spring/Spring.Core.Tests/Context/Config/ComponentScanObjectDefinitionParserTests.cs b/test/Spring/Spring.Core.Tests/Context/Config/ComponentScanObjectDefinitionParserTests.cs index 86ae53dd..f17b4b28 100644 --- a/test/Spring/Spring.Core.Tests/Context/Config/ComponentScanObjectDefinitionParserTests.cs +++ b/test/Spring/Spring.Core.Tests/Context/Config/ComponentScanObjectDefinitionParserTests.cs @@ -119,6 +119,15 @@ namespace Spring.Context.Config Assert.That(prototypeDef.IsLazyInit, Is.True); } + [Test] + public void ComponentsUseDefaultAutoWire() + { + _applicationContext = new XmlApplicationContext(ReadOnlyXmlTestResource.GetFilePath("ConfigFiles.ComponentScan5.xml", GetType())); + var prototypeDef = _applicationContext.ObjectFactory.GetObjectDefinition("Prototype"); + + Assert.That(prototypeDef.AutowireMode == AutoWiringMode.ByName); + } + [Test] public void ComponentWithQualifier() { diff --git a/test/Spring/Spring.Core.Tests/Context/Config/ConfigFiles/ComponentScan5.xml b/test/Spring/Spring.Core.Tests/Context/Config/ConfigFiles/ComponentScan5.xml index 85eb51a7..30b6dbe4 100644 --- a/test/Spring/Spring.Core.Tests/Context/Config/ConfigFiles/ComponentScan5.xml +++ b/test/Spring/Spring.Core.Tests/Context/Config/ConfigFiles/ComponentScan5.xml @@ -1,7 +1,7 @@  + default-lazy-init="true" default-autowire="byName">