public CallDataCollector() { proxyFactory = new ProxyFactory(); proxyFactory.AddInterface(typeof(TWcfContract)); foreach (var interf in typeof(TWcfContract).GetInterfaces()) { proxyFactory.AddInterface(interf); } this.proxyFactory.AddAdvice(this); this.callDataCollectorDynProxy = (TWcfContract)proxyFactory.GetProxy(); }
/// <summary> /// Intercepts an exported value. /// </summary> /// <param name="value">The value to be intercepted.</param> /// <returns>Intercepted value.</returns> public object Intercept(object value) { var interfaces = value.GetType().GetInterfaces(); ProxyFactory factory = new ProxyFactory(value); foreach (var intf in interfaces) { factory.AddInterface(intf); } if (this.advices != null) { foreach (var advice in this.advices) { factory.AddAdvice(advice); } } else { foreach (var advisor in this.advisors) { factory.AddAdvisor(advisor); } } return factory.GetProxy(); }
private object CreateProxy() { var proxy = new ProxyFactory(); proxy.AddInterface(this.ServiceInterface); proxy.AddAdvice(this); proxy.Target = this.Service; return(proxy.GetProxy()); }
private IRepositoryInterface CreateProxy(RepositoryInterfaceImpl target) { MapPersistenceExceptionTranslator mpet = new MapPersistenceExceptionTranslator(); mpet.AddTranslation(persistenceException, new InvalidDataAccessApiUsageException("", persistenceException)); ProxyFactory pf = new ProxyFactory(target); pf.AddInterface(typeof(IRepositoryInterface)); AddPersistenceExceptionTranslation(pf, mpet); return((IRepositoryInterface)pf.GetProxy()); }
/// <summary> /// Initialize the proxy. /// </summary> private void InitializeProxy() { if (this.adviceChain.Length == 0) { return; } var factory = new ProxyFactory(); foreach (var advice in this.adviceChain) { factory.AddAdvisor(new DefaultPointcutAdvisor(TruePointcut.True, advice)); } factory.ProxyTargetType = false; factory.AddInterface(typeof(IContainerDelegate)); factory.Target = this.containerDelegate; this.proxy = (IContainerDelegate)factory.GetProxy(); }
/// <summary> /// Create an AOP proxy for the given object. /// </summary> /// <param name="targetType">Type of the object.</param> /// <param name="targetName">The name of the object.</param> /// <param name="specificInterceptors">The set of interceptors that is specific to this /// object (may be empty but not null)</param> /// <param name="targetSource">The target source for the proxy, already pre-configured to access the object.</param> /// <returns>The AOP Proxy for the object.</returns> protected virtual object CreateProxy(Type targetType, string targetName, object[] specificInterceptors, ITargetSource targetSource) { ProxyFactory proxyFactory = CreateProxyFactory(); // copy our properties (proxyTargetClass) inherited from ProxyConfig proxyFactory.CopyFrom(this); object target = targetSource.GetTarget(); if (!ProxyTargetType) { // Must allow for introductions; can't just set interfaces to // the target's interfaces only. Type[] targetInterfaceTypes = AopUtils.GetAllInterfacesFromType(targetType); foreach (Type interfaceType in targetInterfaceTypes) { proxyFactory.AddInterface(interfaceType); } } IAdvisor[] advisors = BuildAdvisors(targetName, specificInterceptors); foreach (IAdvisor advisor in advisors) { if (advisor is IIntroductionAdvisor) { proxyFactory.AddIntroduction((IIntroductionAdvisor)advisor); } else { proxyFactory.AddAdvisor(advisor); } } proxyFactory.TargetSource = targetSource; CustomizeProxyFactory(proxyFactory); proxyFactory.IsFrozen = freezeProxy; return(proxyFactory.GetProxy()); }
public void DoesNotCacheWithDifferentInterfaces() { ProxyFactory advisedSupport = new ProxyFactory(new TestObject()); CreateAopProxy(advisedSupport); advisedSupport = new ProxyFactory(new TestObject()); advisedSupport.AddInterface(typeof(IPerson)); CreateAopProxy(advisedSupport); AssertAopProxyTypeCacheCount(2); // Same with Introductions advisedSupport = new ProxyFactory(new TestObject()); TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(); ti.TimeStamp = new DateTime(666L); IIntroductionAdvisor introduction = new DefaultIntroductionAdvisor(ti, typeof(ITimeStamped)); advisedSupport.AddIntroduction(introduction); CreateAopProxy(advisedSupport); AssertAopProxyTypeCacheCount(3); }