private object NewPrototypeInstance() { // in the case of a prototype, we need to give the proxy // an independent instance of the configuration... #region Instrumentation if (logger.IsDebugEnabled) { logger.Debug("Creating copy of prototype ProxyFactoryObject config: " + this); } #endregion // The copy needs a fresh advisor chain, and a fresh TargetSource. ITargetSource targetSource = FreshTargetSource(); IList<IAdvisor> advisorChain = FreshAdvisorChain(); IList<IIntroductionAdvisor> introductionChain = FreshIntroductionChain(); AdvisedSupport copy = new AdvisedSupport(); copy.CopyConfigurationFrom(this, targetSource, advisorChain, introductionChain); #region Instrumentation if (logger.IsDebugEnabled) { logger.Debug("Using ProxyConfig: " + copy); } #endregion object generatedProxy = copy.CreateAopProxy().GetProxy(); base.IsFrozen = this.freezeProxy; // freeze after creating proxy to allow for interface autodetection return generatedProxy; }
/// <summary> /// Creates a new instance of the channelmanager. /// </summary> /// <returns>New instance of the channelmanager</returns> public object GetObject() { if (proxyConstructor == null || interceptorConstructor == null) { GenerateProxy(); } object channelProxy = ObjectUtils.InstantiateType(proxyConstructor, ObjectUtils.EmptyObjects); object interceptorProxy = ObjectUtils.InstantiateType(interceptorConstructor, ObjectUtils.EmptyObjects); AdvisedSupport advisedSupport = new AdvisedSupport(new Type[] { ChannelType }); advisedSupport.AddAdvice((IAdvice)interceptorProxy); advisedSupport.Target = channelProxy; advisedSupport.ProxyTargetType = true; var proxy = advisedSupport.AopProxyFactory.CreateAopProxy(advisedSupport); SetDefaultValues(channelProxy); return proxy; }
public void IgnoresAdvisorDuplicates() { CountingBeforeAdvice cba1 = new CountingBeforeAdvice(); IAdvisor advisor1 = new DefaultPointcutAdvisor(cba1); AdvisedSupport advSup = new AdvisedSupport(); advSup.AddAdvisor(advisor1); advSup.AddAdvisor(advisor1); Assert.AreEqual(1, advSup.Advisors.Length); }
/// <summary> /// Copies the configuration from the supplied other /// <see cref="Spring.Aop.Framework.AdvisedSupport"/> into this instance. /// </summary> /// <remarks> /// <p> /// Useful when this instance has been created using the no-argument /// constructor, and needs to get all of its confiuration data from /// another <see cref="Spring.Aop.Framework.AdvisedSupport"/> (most /// usually to have an independant copy of said configuration data). /// </p> /// </remarks> /// <param name="other"> /// The <see cref="Spring.Aop.Framework.AdvisedSupport"/> instance /// containing the configiration data that is to be copied into this /// instance. /// </param> /// <param name="targetSource">the new target source</param> /// <param name="advisors">the advisors for the chain</param> /// <param name="introductions">the introductions for the chain</param> protected internal virtual void CopyConfigurationFrom(AdvisedSupport other, ITargetSource targetSource, IList advisors, IList introductions) { CopyFrom(other); this.AdvisorChainFactory = other.advisorChainFactory; this.m_targetSource = targetSource; // this.cachedProxyType = other.cachedProxyType; // this.cachedProxyConstructor = other.cachedProxyConstructor; this.Interfaces = (Type[]) CollectionUtils.ToArray(other.Interfaces, typeof(Type)); foreach (Type intf in other.interfaceMap.Keys) { this.interfaceMap[intf] = other.interfaceMap[intf]; } this._advisors = new ArrayList(); foreach (IAdvisor advisor in advisors) { AssertUtils.ArgumentNotNull(advisor, "Advisor must not be null"); AddAdvisor(advisor); } this._introductions = new ArrayList(); foreach (IIntroductionAdvisor advisor in introductions) { // TODO (EE): implement // ValidateIntroductionAdvisor((IIntroductionAdvisor) advisor); AssertUtils.ArgumentNotNull(advisor, "IntroductionAdvisor must not be null"); AddIntroduction(advisor); } UpdateAdvisorsArray(); AdviceChanged(); }
/// <summary> /// Copies the configuration from the supplied other /// <see cref="Spring.Aop.Framework.AdvisedSupport"/> into this instance. /// </summary> /// <remarks> /// <p> /// Useful when this instance has been created using the no-argument /// constructor, and needs to get all of its confiuration data from /// another <see cref="Spring.Aop.Framework.AdvisedSupport"/> (most /// usually to have an independant copy of said configuration data). /// </p> /// </remarks> /// <param name="other"> /// The <see cref="Spring.Aop.Framework.AdvisedSupport"/> instance /// containing the configiration data that is to be copied into this /// instance. /// </param> protected internal virtual void CopyConfigurationFrom(AdvisedSupport other) { CopyConfigurationFrom(other, other.TargetSource, new ArrayList(other.Advisors), new ArrayList(other.Introductions)); }
/// <summary> /// Invoked when advice is changed after a proxy is created. /// </summary> /// <param name="source"> /// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source. /// </param> public void AdviceChanged(AdvisedSupport source) { methodCache.Clear(); }
/// <summary> /// Invoked when the first proxy is created. /// </summary> /// <param name="source"> /// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source. /// </param> public void Activated(AdvisedSupport source) { }
/// <summary> /// Invoked when interfaces are changed after a proxy is created. /// </summary> /// <param name="source"> /// The relevant <see cref="Spring.Aop.Framework.AdvisedSupport"/> source. /// </param> public void InterfacesChanged(AdvisedSupport source) { }