From 606e441c733ef77efc01729ae9642728e2941013 Mon Sep 17 00:00:00 2001 From: eeichinger Date: Wed, 2 Dec 2009 01:05:13 +0000 Subject: [PATCH] minor polishing introduced ICustomValueReferenceHolder for better fluent configuration extensibility --- .../AbstractAutowireCapableObjectFactory.cs | 4 ++-- .../Factory/Support/ConstructorResolver.cs | 7 +++++-- .../Support/ObjectDefinitionValueResolver.cs | 21 ++++++++++++++----- .../Spring.Core/Spring.Core.2003.csproj | 5 +++++ .../Spring.Core/Spring.Core.2005.csproj | 1 + .../Spring.Core/Spring.Core.2008.csproj | 1 + 6 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs index 1ea1dff2..46a4bcca 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs @@ -1068,7 +1068,7 @@ namespace Spring.Objects.Factory.Support protected virtual IObjectWrapper InstantiateUsingFactoryMethod(string name, RootObjectDefinition definition, object[] arguments) { ConstructorResolver constructorResolver = - new ConstructorResolver(this, this, InstantiationStrategy); + new ConstructorResolver(this, this, InstantiationStrategy, CreateValueResolver()); return constructorResolver.InstantiateUsingFactoryMethod(name, definition, arguments); } @@ -1097,7 +1097,7 @@ namespace Spring.Objects.Factory.Support protected IObjectWrapper AutowireConstructor(string name, RootObjectDefinition definition, ConstructorInfo[] ctors, object[] explicitArgs) { ConstructorResolver constructorResolver = - new ConstructorResolver(this, this, InstantiationStrategy); + new ConstructorResolver(this, this, InstantiationStrategy, CreateValueResolver()); return constructorResolver.AutowireConstructor(name, definition, ctors, explicitArgs); } diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/ConstructorResolver.cs b/src/Spring/Spring.Core/Objects/Factory/Support/ConstructorResolver.cs index ea5e7922..4802736f 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/ConstructorResolver.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/ConstructorResolver.cs @@ -51,6 +51,7 @@ namespace Spring.Objects.Factory.Support private readonly IAutowireCapableObjectFactory autowireFactory; private readonly IInstantiationStrategy instantiationStrategy; + private readonly ObjectDefinitionValueResolver valueResolver; /// /// Initializes a new instance of the class for the given factory @@ -59,12 +60,14 @@ namespace Spring.Objects.Factory.Support /// The object factory to work with. /// The object factory as IAutowireCapableObjectFactory. /// The instantiation strategy for creating objects. + /// the resolver to resolve property value placeholders if any public ConstructorResolver(AbstractObjectFactory objectFactory, IAutowireCapableObjectFactory autowireFactory, - IInstantiationStrategy instantiationStrategy) + IInstantiationStrategy instantiationStrategy, ObjectDefinitionValueResolver valueResolver) { this.objectFactory = objectFactory; this.autowireFactory = autowireFactory; this.instantiationStrategy = instantiationStrategy; + this.valueResolver = valueResolver; } /// @@ -516,7 +519,7 @@ namespace Spring.Objects.Factory.Support ConstructorArgumentValues cargs, ConstructorArgumentValues resolvedValues) { - ObjectDefinitionValueResolver valueResolver = new ObjectDefinitionValueResolver(objectFactory); +// ObjectDefinitionValueResolver valueResolver = new ObjectDefinitionValueResolver(objectFactory); int minNrOfArgs = cargs.ArgumentCount; foreach (DictionaryEntry entry in cargs.IndexedArgumentValues) diff --git a/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionValueResolver.cs b/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionValueResolver.cs index 321e62c0..4c591745 100644 --- a/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionValueResolver.cs +++ b/src/Spring/Spring.Core/Objects/Factory/Support/ObjectDefinitionValueResolver.cs @@ -117,11 +117,18 @@ namespace Spring.Objects.Factory.Support /// /// TODO /// - /// - /// - /// - /// - /// + /// + /// The name of the object that is having the value of one of its properties resolved. + /// + /// + /// The definition of the named object. + /// + /// + /// The name of the property the value of which is being resolved. + /// + /// + /// The value of the property that is being resolved. + /// private object ResolvePropertyValue(string name, IObjectDefinition definition, string argumentName, object argumentValue) { object resolvedValue = null; @@ -133,6 +140,10 @@ namespace Spring.Objects.Factory.Support { resolvedValue = argumentValue; } + else if (argumentValue is ICustomValueReferenceHolder) + { + resolvedValue = ((ICustomValueReferenceHolder) argumentValue).Resolve(objectFactory, name, definition, argumentName, argumentValue); + } else if (argumentValue is ObjectDefinitionHolder) { // contains an IObjectDefinition with name and aliases... diff --git a/src/Spring/Spring.Core/Spring.Core.2003.csproj b/src/Spring/Spring.Core/Spring.Core.2003.csproj index 0e9cd14e..7b5eb9b5 100644 --- a/src/Spring/Spring.Core/Spring.Core.2003.csproj +++ b/src/Spring/Spring.Core/Spring.Core.2003.csproj @@ -2070,6 +2070,11 @@ SubType = "Code" BuildAction = "Compile" /> + + diff --git a/src/Spring/Spring.Core/Spring.Core.2008.csproj b/src/Spring/Spring.Core/Spring.Core.2008.csproj index b5a6d191..151271a5 100644 --- a/src/Spring/Spring.Core/Spring.Core.2008.csproj +++ b/src/Spring/Spring.Core/Spring.Core.2008.csproj @@ -665,6 +665,7 @@ +