public void IncludingAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName }); Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IncludeAncestors = true; NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) { IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(); if (Logger.IsInfoEnabled) Logger.Info("Iniciando proceso para establecer el alcance de los services y controllers"); foreach (string objectDefinitionName in objectDefinitionNames) { IObjectDefinition objectDefinition = factory.GetObjectDefinition(objectDefinitionName); if (objectDefinition is ScannedGenericObjectDefinition) { var componentAttribute = Attribute.GetCustomAttribute(objectDefinition.ObjectType, typeof (ComponentAttribute), true) as ComponentAttribute; if ( (componentAttribute is ControllerAttribute) || (WcfServices && componentAttribute is ServiceAttribute) ) { if (Logger.IsInfoEnabled) Logger.InfoFormat("Estableciendo alcance para la definición {0}", objectDefinitionName); objectDefinition.Scope = "prototype"; } } } }
public void WithDefaultProperties() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string [] { defName }); Expect.Call(mock.GetObjectDefinition(defName)).Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); mocks.VerifyAll(); }
/// <summary> /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all /// object in the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected virtual void ProcessProperties(IConfigurableListableObjectFactory factory) { CompositeVariableSource compositeVariableSource = new CompositeVariableSource(variableSourceList); TextProcessor tp = new TextProcessor(this, compositeVariableSource); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables)); var objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors); if (definition == null) { continue; } try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } }
public void UsingCustomMarkers() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "#hope.floats#"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#"; cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
public void ChokesOnCircularReferenceToPlaceHolder() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${foo}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "ba${foo}r"; properties.Add("foo", expectedName); IConfigurableListableObjectFactory mock = (IConfigurableListableObjectFactory)mocks.CreateMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mock.GetObjectDefinitionNames()).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null)).IgnoreArguments().Return(def); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; try { cfg.PostProcessObjectFactory(mock); Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point."); } catch (ObjectDefinitionStoreException) { } mocks.VerifyAll(); }
public void ChokesOnCircularReferenceToPlaceHolder() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${foo}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "ba${foo}r"; properties.Add("foo", expectedName); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string[] { "foo" }); A.CallTo(() => mock.GetObjectDefinition(null, false)).WithAnyArguments().Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; try { cfg.PostProcessObjectFactory(mock); Assert.Fail("Should have raised an ObjectDefinitionStoreException by this point."); } catch (ObjectDefinitionStoreException) { } }
public void UsingCustomMarkers() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "#hope.floats#"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(false)).Returns(new string[] { "foo" }); A.CallTo(() => mock.GetObjectDefinition(null, false)).WithAnyArguments().Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.PlaceholderPrefix = cfg.PlaceholderSuffix = "#"; cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); A.CallTo(() => mock.AddEmbeddedValueResolver(null)).WithAnyArguments().MustHaveHappened(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
/// <summary> /// Apply the given properties to the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <param name="props">The properties to apply.</param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) { PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables); IList <string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors); if (definition == null) { logger.ErrorFormat("'{0}' can't be found in factorys' '{1}' object definition (includeAncestor {2})", name, factory, includeAncestors); continue; } try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } factory.AddEmbeddedValueResolver(resolveAdapter); }
public void IncludingAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mock.GetObjectDefinitionNames(true)).Returns(new string[] { defName }); A.CallTo(() => mock.GetObjectDefinition(defName, true)).Returns(def); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IncludeAncestors = true; NameValueCollection defaultProperties = new NameValueCollection(); const string expectedName = "Rick Evans"; defaultProperties.Add(theProperty, expectedName); cfg.Properties = defaultProperties; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(expectedName, def.PropertyValues.GetPropertyValue(theProperty).Value, "Property placeholder value was not replaced with the resolved value."); A.CallTo(() => mock.AddEmbeddedValueResolver(A <IStringValueResolver> ._)).MustHaveHappened(); }
/// <summary> /// Allows for custom modification of an application context's object definitions. /// </summary> /// <remarks> /// <p> /// If the object name matches, replaces the type by a AOP proxied type based on inheritance. /// </p> /// </remarks> public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) { IList <string> objectDefinitionNames = factory.GetObjectDefinitionNames(); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; if (IsObjectNameMatch(name)) { IConfigurableObjectDefinition definition = factory.GetObjectDefinition(name) as IConfigurableObjectDefinition; if (definition == null || IsInfrastructureType(definition.ObjectType, name)) { continue; } ProxyFactory pf = CreateProxyFactory(definition.ObjectType, name); InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(pf); iaptb.ProxyDeclaredMembersOnly = this.ProxyDeclaredMembersOnly; Type type = iaptb.BuildProxyType(); definition.ObjectType = type; definition.ConstructorArgumentValues.AddIndexedArgumentValue(definition.ConstructorArgumentValues.ArgumentCount, pf); } } }
public void InlcludeAncestors() { const string defName = "foo"; const string placeholder = "${name}"; MutablePropertyValues pvs = new MutablePropertyValues(); const string theProperty = "name"; pvs.Add(theProperty, placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(true)).Return(new string[] { defName }); Expect.Call(mock.GetObjectDefinition(defName, true)).Return(def); mocks.ReplayAll(); VariablePlaceholderConfigurer vpc = new VariablePlaceholderConfigurer(); vpc.IgnoreUnresolvablePlaceholders = true; vpc.VariableSource = new DictionaryVariableSource(new string[] { "name", "Erich" }); vpc.IncludeAncestors = true; vpc.PostProcessObjectFactory(mock); mocks.VerifyAll(); }
public void WithIgnoreUnresolvablePlaceholder() { const string defName = "foo"; const string placeholder = "${name}"; TestObject foo = new TestObject(placeholder, 30); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.Add("name", placeholder); RootObjectDefinition def = new RootObjectDefinition(typeof(TestObject), pvs); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string [] { defName }); Expect.Call(mock.GetObjectDefinition(defName, false)).Return(def); Expect.Call(() => mock.AddEmbeddedValueResolver(null)).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreUnresolvablePlaceholders = true; cfg.PostProcessObjectFactory(mock); Assert.AreEqual(placeholder, foo.Name); mocks.VerifyAll(); }
public void ReplacesNamedCtorArgument() { RootObjectDefinition def = new RootObjectDefinition(); def.ObjectType = typeof(TestObject); ConstructorArgumentValues args = new ConstructorArgumentValues(); args.AddNamedArgumentValue("name", "${hope.floats}"); def.ConstructorArgumentValues = args; NameValueCollection properties = new NameValueCollection(); const string expectedName = "Rick"; properties.Add("hope.floats", expectedName); IConfigurableListableObjectFactory mock = mocks.StrictMock <IConfigurableListableObjectFactory>(); Expect.Call(mock.GetObjectDefinitionNames(false)).Return(new string[] { "foo" }); Expect.Call(mock.GetObjectDefinition(null, false)).IgnoreArguments().Return(def); Expect.Call(delegate { mock.AddEmbeddedValueResolver(null); }).IgnoreArguments(); mocks.ReplayAll(); PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.Properties = properties; cfg.PostProcessObjectFactory(mock); mocks.VerifyAll(); Assert.AreEqual(expectedName, def.ConstructorArgumentValues.GetNamedArgumentValue("name").Value, "Named argument placeholder value was not replaced."); }
private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory) { ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer(objectFactory); IList <string> objectNames = objectFactory.GetObjectDefinitionNames(); foreach (string name in objectNames) { IObjectDefinition objDef = objectFactory.GetObjectDefinition(name); if (((AbstractObjectDefinition)objDef).HasObjectType) { if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null) { //TODO check type of object isn't infrastructure type. Type configClass = objDef.ObjectType; Type enhancedClass = enhancer.Enhance(configClass); Logger.Debug(m => m("Replacing object definition '{0}' existing class '{1}' with enhanced class", name, configClass.FullName)); ((IConfigurableObjectDefinition)objDef).ObjectType = enhancedClass; } } } }
public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = true; IResource mockResource = A.Fake <IResource>(); A.CallTo(() => mockResource.Exists).Returns(false); cfg.Location = mockResource; cfg.ConfigSections = new string[] { "" }; IConfigurableListableObjectFactory mockFactory = A.Fake <IConfigurableListableObjectFactory>(); A.CallTo(() => mockFactory.GetObjectDefinitionNames(false)).Returns(new string[] {}); cfg.PostProcessObjectFactory(mockFactory); }
public void DoesNotChokeOnBadResourceLocationIfIgnoreBadResourcesFlagSetToTrue() { PropertyPlaceholderConfigurer cfg = new PropertyPlaceholderConfigurer(); cfg.IgnoreResourceNotFound = true; IResource mockResource = (IResource)mocks.CreateMock(typeof(IResource)); Expect.Call(mockResource.Exists).Return(false); cfg.Location = mockResource; cfg.ConfigSections = new string[] { "" }; IConfigurableListableObjectFactory mockFactory = (IConfigurableListableObjectFactory)mocks.DynamicMock(typeof(IConfigurableListableObjectFactory)); Expect.Call(mockFactory.GetObjectDefinitionNames()).Return(new string[] {}); mocks.ReplayAll(); cfg.PostProcessObjectFactory(mockFactory); mocks.VerifyAll(); }
/// <summary> /// Apply the given properties to the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <param name="props">The properties to apply.</param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) { PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(resolveAdapter.ParseAndResolveVariables)); string[] objectDefinitionNames = factory.GetObjectDefinitionNames(); for (int i = 0; i < objectDefinitionNames.Length; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name); try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } }
private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory) { string[] objectNames = objectFactory.GetObjectDefinitionNames(); foreach (string t in objectNames) { IObjectDefinition objDef = objectFactory.GetObjectDefinition(t); if (((AbstractObjectDefinition)objDef).HasObjectType) { if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null) { ProxyFactory proxyFactory = new ProxyFactory(); proxyFactory.ProxyTargetAttributes = true; proxyFactory.Interfaces = Type.EmptyTypes; proxyFactory.TargetSource = new ObjectFactoryTargetSource(t, objectFactory); SpringObjectMethodInterceptor methodInterceptor = new SpringObjectMethodInterceptor(objectFactory); proxyFactory.AddAdvice(methodInterceptor); //TODO check type of object isn't infrastructure type. InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(proxyFactory); //iaptb.ProxyDeclaredMembersOnly = true; // make configurable. ((IConfigurableObjectDefinition)objDef).ObjectType = iaptb.BuildProxyType(); objDef.ConstructorArgumentValues.AddIndexedArgumentValue(objDef.ConstructorArgumentValues.ArgumentCount, proxyFactory); } } } }
private void EnhanceConfigurationClasses(IConfigurableListableObjectFactory objectFactory) { ConfigurationClassEnhancer enhancer = new ConfigurationClassEnhancer(objectFactory); IList<string> objectNames = objectFactory.GetObjectDefinitionNames(); foreach (string name in objectNames) { IObjectDefinition objDef = objectFactory.GetObjectDefinition(name); if (((AbstractObjectDefinition)objDef).HasObjectType) { if (Attribute.GetCustomAttribute(objDef.ObjectType, typeof(ConfigurationAttribute)) != null) { //TODO check type of object isn't infrastructure type. Type configClass = objDef.ObjectType; Type enhancedClass = enhancer.Enhance(configClass); Logger.Debug(m => m("Replacing object definition '{0}' existing class '{1}' with enhanced class", name, configClass.FullName)); ((IConfigurableObjectDefinition)objDef).ObjectType = enhancedClass; } } } }
/// <summary> /// Apply the property replacement using the specified <see cref="IVariableSource"/>s for all /// object in the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected virtual void ProcessProperties( IConfigurableListableObjectFactory factory ) { CompositeVariableSource compositeVariableSource = new CompositeVariableSource(variableSourceList); TextProcessor tp = new TextProcessor(this, compositeVariableSource); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(new ObjectDefinitionVisitor.ResolveHandler(tp.ParseAndResolveVariables)); IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition( name, includeAncestors ); if (definition == null) continue; try { visitor.VisitObjectDefinition( definition ); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message ); } } }
/// <summary> /// Apply the given properties to the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <param name="props">The properties to apply.</param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) { PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables); IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(includeAncestors); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name, includeAncestors); if (definition == null) { logger.ErrorFormat("'{0}' can't be found in factorys' '{1}' object definition (includeAncestor {2})", name, factory, includeAncestors); continue; } try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } factory.AddEmbeddedValueResolver(resolveAdapter); }
/// <summary> /// Allows for custom modification of an application context's object definitions. /// </summary> /// <remarks> /// <p> /// If the object name matches, replaces the type by a AOP proxied type based on inheritance. /// </p> /// </remarks> public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) { IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; if (IsObjectNameMatch(name)) { var definition = factory.GetObjectDefinition(name) as IConfigurableObjectDefinition; if (definition == null || IsInfrastructureType(definition.ObjectType, name)) { continue; } ProxyFactory pf = CreateProxyFactory(definition.ObjectType, name); InheritanceAopProxyTypeBuilder iaptb = new InheritanceAopProxyTypeBuilder(pf); iaptb.ProxyDeclaredMembersOnly = this.ProxyDeclaredMembersOnly; Type type = iaptb.BuildProxyType(); definition.ObjectType = type; definition.ConstructorArgumentValues.AddIndexedArgumentValue(definition.ConstructorArgumentValues.ArgumentCount, pf); } } }
/// <summary> /// Apply the given properties to the supplied /// <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/>. /// </summary> /// <param name="factory"> /// The <see cref="Spring.Objects.Factory.Config.IConfigurableListableObjectFactory"/> /// used by the application context. /// </param> /// <param name="props">The properties to apply.</param> /// <exception cref="Spring.Objects.ObjectsException"> /// If an error occured. /// </exception> protected override void ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props) { PlaceholderResolveHandlerAdapter resolveAdapter = new PlaceholderResolveHandlerAdapter(this, props); ObjectDefinitionVisitor visitor = new ObjectDefinitionVisitor(resolveAdapter.ParseAndResolveVariables); IList<string> objectDefinitionNames = factory.GetObjectDefinitionNames(); for (int i = 0; i < objectDefinitionNames.Count; ++i) { string name = objectDefinitionNames[i]; IObjectDefinition definition = factory.GetObjectDefinition(name); try { visitor.VisitObjectDefinition(definition); } catch (ObjectDefinitionStoreException ex) { throw new ObjectDefinitionStoreException( definition.ResourceDescription, name, ex.Message); } } factory.AddEmbeddedValueResolver(resolveAdapter); }
public void PostProcessObjectFactory(IConfigurableListableObjectFactory factory) { string[] lnames = factory.GetObjectDefinitionNames(); names.AddRange(lnames); }