Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv27636/Objects/Factory/Support
Modified Files:
AbstractAutowireCapableObjectFactory.cs AutowireUtils.cs
Log Message:
SPRNET-907 - Add Required attribute and RequiredObjectFactoryPostProcessor, allowing to enforce required object properties
Index: AutowireUtils.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support/AutowireUtils.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** AutowireUtils.cs 31 Jul 2007 03:47:39 -0000 1.6
--- AutowireUtils.cs 2 Apr 2008 18:02:24 -0000 1.7
***************
*** 24,27 ****
--- 24,28 ----
using System.Collections;
using System.Reflection;
+ using Spring.Collections;
using Spring.Core;
using Spring.Objects.Factory.Config;
***************
*** 169,172 ****
--- 170,185 ----
}
+ /// <summary>
+ /// Determines whether the given object property is excluded from dependency checks.
+ /// </summary>
+ /// <param name="pi">The PropertyInfo of the object property.</param>
+ /// <returns>
+ /// <c>true</c> if is excluded from dependency check; otherwise, <c>false</c>.
+ /// </returns>
+ public static Boolean IsExcludedFromDependencyCheck(PropertyInfo pi)
+ {
+ return (pi.GetSetMethod() == null) ? false : true;
+ }
+
/// <summary>
/// Sorts the supplied <paramref name="constructors"/>, preferring
***************
*** 244,247 ****
--- 257,286 ----
#endregion
+
+ /// <summary>
+ /// Determines whether the setter property is defined in any of the given interfaces.
+ /// </summary>
+ /// <param name="propertyInfo">The PropertyInfo of the object property</param>
+ /// <param name="interfaces">The ISet of interfaces.</param>
+ /// <returns>
+ /// <c>true</c> if setter property is defined in interface; otherwise, <c>false</c>.
+ /// </returns>
+ public static bool IsSetterDefinedInInterface(PropertyInfo propertyInfo, ISet interfaces)
+ {
+ MethodInfo setter = propertyInfo.GetSetMethod();
+ if (setter != null)
+ {
+ Type targetType = setter.DeclaringType;
+ foreach (Type interfaceType in interfaces)
+ {
+ if (interfaceType.IsAssignableFrom(targetType) &&
+ ReflectionUtils.GetMethod(interfaceType, setter.Name, ReflectionUtils.GetParameterTypes(setter)) != null)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}
}
\ No newline at end of file
Index: AbstractAutowireCapableObjectFactory.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Core/Objects/Factory/Support/AbstractAutowireCapableObjectFactory.cs,v
retrieving revision 1.85
retrieving revision 1.86
diff -C2 -d -r1.85 -r1.86
*** AbstractAutowireCapableObjectFactory.cs 20 Mar 2008 10:35:54 -0000 1.85
--- AbstractAutowireCapableObjectFactory.cs 2 Apr 2008 18:02:24 -0000 1.86
***************
*** 113,117 ****
/// <param name="parentFactory">The parent object factory, or <see langword="null"/> if none.</param>
protected AbstractAutowireCapableObjectFactory(bool caseSensitive, IObjectFactory parentFactory) : base(caseSensitive, parentFactory)
! {}
#endregion
--- 113,120 ----
/// <param name="parentFactory">The parent object factory, or <see langword="null"/> if none.</param>
protected AbstractAutowireCapableObjectFactory(bool caseSensitive, IObjectFactory parentFactory) : base(caseSensitive, parentFactory)
! {
! this.IgnoreDependencyInterface(typeof(IObjectFactoryAware));
! this.IgnoreDependencyInterface(typeof(IObjectNameAware));
! }
#endregion
***************
*** 500,504 ****
{
PropertyInfo[] filteredPropInfo = FilterPropertyInfoForDependencyCheck(wrapper);
! if (HasInstantiationAwareBeanPostProcessors)
{
foreach (IObjectPostProcessor processor in ObjectPostProcessors)
--- 503,507 ----
{
PropertyInfo[] filteredPropInfo = FilterPropertyInfoForDependencyCheck(wrapper);
! if (hasInstAwareOpps)
{
foreach (IObjectPostProcessor processor in ObjectPostProcessors)
***************
*** 706,709 ****
--- 709,728 ----
/// <summary>
+ /// Ignore the given dependency type for autowiring
+ /// </summary>
+ /// <remarks>
+ /// This will typically be used by application contexts to register
+ /// dependencies that are resolved in other ways, like IOjbectFactory through
+ /// IObjectFactoryAware or IApplicationContext through IApplicationContextAware.
+ /// By default, IObjectFactoryAware and IObjectName interfaces are ignored.
+ /// For further types to ignore, invoke this method for each type.
+ /// </remarks>
+ /// <seealso cref="Spring.Objects.Factory.Config.IConfigurableObjectFactory.IgnoreDependencyType"/>.
+ public void IgnoreDependencyInterface(Type type)
+ {
+ ignoredDependencyInterfaces.Add(type);
+ }
+
+ /// <summary>
/// Create an object instance for the given object definition.
/// </summary>
***************
*** 1484,1487 ****
--- 1503,1507 ----
}
}
+
filtered = (PropertyInfo[]) list.ToArray(typeof(PropertyInfo));
filteredPropertyDescriptorsCache.Add(wrapper.WrappedType, filtered);
***************
*** 1494,1498 ****
private bool IsExcludedFromDependencyCheck(PropertyInfo pi)
{
! return IgnoredDependencyTypes.Contains(pi.PropertyType);
}
--- 1514,1526 ----
private bool IsExcludedFromDependencyCheck(PropertyInfo pi)
{
! bool b1 = !pi.CanWrite; //AutowireUtils.IsExcludedFromDependencyCheck(pi);
! bool b2 = IgnoredDependencyTypes.Contains(pi.PropertyType);
! bool b3 = AutowireUtils.IsSetterDefinedInInterface(pi, ignoredDependencyInterfaces);
! return b1 || b2 || b3;
! /*
! return AutowireUtils.IsExcludedFromDependencyCheck(pi) ||
! IgnoredDependencyTypes.Contains(pi.PropertyType) ||
! AutowireUtils.IsSetterDefinedInInterface(pi, ignoredDependencyInterfaces);
! */
}
***************
*** 2325,2328 ****
--- 2353,2363 ----
private IDictionary filteredPropertyDescriptorsCache = new Hashtable();
+ /// <summary>
+ /// Dependency interfaces to ignore on dependency check and autowire, as Set of
+ /// Class objects. By default, only the IObjectFactoryAware and IObjectNameAware
+ /// interfaces are ignored.
+ /// </summary>
+ private ISet ignoredDependencyInterfaces = new HybridSet();
+
#endregion
}
|