本文整理汇总了C#中Spring.Aop.Framework.ProxyFactory.GetProxy方法的典型用法代码示例。如果您正苦于以下问题:C# ProxyFactory.GetProxy方法的具体用法?C# ProxyFactory.GetProxy怎么用?C# ProxyFactory.GetProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spring.Aop.Framework.ProxyFactory
的用法示例。
在下文中一共展示了ProxyFactory.GetProxy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// The main entry point for the application.
/// </summary>
public static void Main(string[] args)
{
try
{
// Create AOP proxy programmatically.
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ConsoleLoggingBeforeAdvice());
factory.AddAdvice(new ConsoleLoggingAfterAdvice());
factory.AddAdvice(new ConsoleLoggingThrowsAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute();
if (command.IsUndoCapable)
{
command.UnExecute();
}
}
catch (Exception ex)
{
Console.Out.WriteLine();
Console.Out.WriteLine(ex);
}
finally
{
Console.Out.WriteLine();
Console.Out.WriteLine("--- hit <return> to quit ---");
Console.ReadLine();
}
}
示例2: Main
private static void Main(string[] args)
{
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ConsoleLoggingAroundAdvice());
ICommand command = (ICommand)factory.GetProxy();
command.Execute("This is the argument");
}
示例3: GetEntity
public static IXMLMailUtil GetEntity()
{
if (entity == null)
{
ProxyFactory factory = new ProxyFactory(new XMLMailUtil());
factory.AddAdvice(new AroundAdvice());
entity = (IXMLMailUtil)factory.GetProxy();
}
return entity;
}
示例4: Advised
protected override object Advised(object target, IPlatformTransactionManager ptm,
ITransactionAttributeSource tas)
{
TransactionInterceptor ti = new TransactionInterceptor();
ti.TransactionManager = ptm;
Assert.AreEqual(ptm, ti.TransactionManager);
ti.TransactionAttributeSource = tas;
Assert.AreEqual(tas, ti.TransactionAttributeSource);
ProxyFactory pf = new ProxyFactory(target);
pf.AddAdvice(0, ti);
return pf.GetProxy();
}
示例5: CreateInventorStore
protected override IInventorRepository CreateInventorStore()
{
Region region = CreateRegion();
cache = new GemFireCache(region);
context.ObjectFactory.RegisterSingleton("inventors", cache);
ProxyFactory pf = new ProxyFactory(new InventorRepository());
pf.AddAdvisors(cacheAspect);
Repository = (IInventorRepository)pf.GetProxy();
return Repository;
}
示例6: Main
static void Main(string[] args)
{
ProxyFactory factory = new ProxyFactory(new ServiceCommand());
factory.AddAdvice(new ExceptionAdvice());
ICommand cc = (ICommand)factory.GetProxy();
cc.Execute();
//cc.DoExecute();
//var ctx = ContextRegistry.GetContext();
//ICommand command = (ICommand)ctx.GetObject("myAfterAdvice");
//command.Execute();
//command.DoExecute();
Console.ReadLine();
}
示例7: GetProxy
private static Contact GetProxy()
{
Contact target = new Contact();
target.FirstName = "Aleksandar";
target.LastName = "Seovic";
ProxyFactory pf = new ProxyFactory(target);
pf.AddAdvisor(new ModificationAdvisor(target.GetType()));
pf.AddIntroduction(new IsModifiedAdvisor());
pf.ProxyTargetType = true;
return (Contact)pf.GetProxy();
}
示例8: Main
static void Main(string[] args)
{
//Person p=new Person();
// p.Pen=new Pen();
// p.Write();
ProxyFactory proxy = new ProxyFactory(new Pen());
//proxy.AddAdvice(new BeforeAdvice());
proxy.AddAdvice(new AroundAdvice());
IWrite p = proxy.GetProxy() as IWrite;
p.Write();
Console.ReadKey();
}
示例9: TestIntroductionInterceptorWithDelegation
public void TestIntroductionInterceptorWithDelegation()
{
TestObject raw = new TestObject();
Assert.IsTrue(! (raw is ITimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
ITimeStampedIntroduction ts = MockRepository.GenerateMock<ITimeStampedIntroduction>();
ts.Stub(x => x.TimeStamp).Return(EXPECTED_TIMESTAMP);
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
factory.AddIntroduction(advisor);
ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
}
示例10: GetServiceProxy
public object GetServiceProxy(Assembly webServiceAssembly, string serviceName)
{
object proxy = webServiceAssembly.CreateInstance(serviceName);
if (proxy == null)
throw new Exception("Cannot create proxy instance");
if (_modifier == null)
return proxy;
var factory = new ProxyFactory(proxy) { ProxyTargetType = true };
factory.AddAdvice(new WebRequestModifyInterceptor(_modifier));
var result = factory.GetProxy();
SetUpMissingValues(proxy, result);
return result;
}
示例11: testIntroductionInterceptorWithDelegation
public void testIntroductionInterceptorWithDelegation()
{
TestObject raw = new TestObject();
Assert.IsTrue(! (raw is ITimeStamped));
ProxyFactory factory = new ProxyFactory(raw);
IDynamicMock tsControl = new DynamicMock(typeof(ITimeStampedIntroduction));
ITimeStampedIntroduction ts = (ITimeStampedIntroduction) tsControl.Object;
tsControl.ExpectAndReturn("TimeStamp", EXPECTED_TIMESTAMP);
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(ts);
factory.AddIntroduction(advisor);
ITimeStamped tsp = (ITimeStamped) factory.GetProxy();
Assert.IsTrue(tsp.TimeStamp == EXPECTED_TIMESTAMP);
tsControl.Verify();
}
示例12: IntegrationTest
public void IntegrationTest()
{
ProxyFactory pf = new ProxyFactory(new TestTarget());
ILog log = (ILog)mocks.CreateMock(typeof(ILog));
SimpleLoggingAdvice loggingAdvice = new SimpleLoggingAdvice(log);
pf.AddAdvice(loggingAdvice);
Expect.Call(log.IsTraceEnabled).Return(true).Repeat.Any();
log.Trace("Entering DoSomething");
log.Trace("Exiting DoSomething");
mocks.ReplayAll();
object proxy = pf.GetProxy();
ITestTarget ptt = (ITestTarget)proxy;
ptt.DoSomething();
mocks.VerifyAll();
}
示例13: Matches
public void Matches()
{
SerializablePerson target = new SerializablePerson();
target.SetAge(27);
ControlFlowPointcut cflow = new ControlFlowPointcut(typeof(One), "GetAge");
ProxyFactory factory = new ProxyFactory(target);
NopInterceptor nop = new NopInterceptor();
IPerson proxied = (IPerson) factory.GetProxy();
factory.AddAdvisor(new DefaultPointcutAdvisor(cflow, nop));
// not advised, not under One...
Assert.AreEqual(target.GetAge(), proxied.GetAge());
Assert.AreEqual(0, nop.Count, "Whoops, appear to be advising when not under One's cflow.");
// will be advised...
One one = new One();
Assert.AreEqual(27, one.GetAge(proxied));
Assert.AreEqual(1, nop.Count, "Not advising when under One's cflow (must be).");
// won't be advised...
Assert.AreEqual(target.GetAge(), new One().NoMatch(proxied));
Assert.AreEqual(1, nop.Count, "Whoops, appear to be advising when under One's cflow scope, BUT NOT under a target method's cflow scope.");
Assert.AreEqual(3, cflow.EvaluationCount, "Pointcut not invoked the correct number of times.");
}
示例14: RemoveAdvisedSupportListener
public void RemoveAdvisedSupportListener()
{
IAdvisedSupportListener listener = MockRepository.GenerateMock<IAdvisedSupportListener>();
ProxyFactory factory = new ProxyFactory(new TestObject());
factory.AddListener(listener);
factory.RemoveListener(listener);
factory.GetProxy();
// check that no lifecycle callback methods were invoked on the listener...
listener.AssertWasNotCalled(x => x.Activated(Arg<AdvisedSupport>.Is.Anything));
listener.AssertWasNotCalled(x => x.AdviceChanged(Arg<AdvisedSupport>.Is.Anything));
listener.AssertWasNotCalled(x => x.InterfacesChanged(Arg<AdvisedSupport>.Is.Anything));
}
示例15: NestedProxiesDontInvokeSameAdviceOrIntroductionTwice
public void NestedProxiesDontInvokeSameAdviceOrIntroductionTwice()
{
MultiProxyingTestClass testObj = new MultiProxyingTestClass();
ProxyFactory pf1 = new ProxyFactory();
pf1.Target = testObj;
NopInterceptor di = new NopInterceptor();
NopInterceptor diUnused = new NopInterceptor(1); // // make instance unique (see SPRNET-847)
TestCountingIntroduction countingMixin = new TestCountingIntroduction();
pf1.AddAdvice(diUnused);
pf1.AddAdvisor(new DefaultPointcutAdvisor(di));
pf1.AddIntroduction(new DefaultIntroductionAdvisor(countingMixin));
object innerProxy = pf1.GetProxy();
ProxyFactory pf2 = new ProxyFactory();
pf2.Target = innerProxy;
pf2.AddAdvice(diUnused);
pf2.AddAdvisor(new DefaultPointcutAdvisor(di));
pf2.AddIntroduction(new DefaultIntroductionAdvisor(countingMixin));
object outerProxy = pf2.GetProxy();
// any advice instance is invoked once only
string result = ((IMultiProxyingTestInterface)outerProxy).TestMethod("arg");
Assert.AreEqual(1, testObj.InvocationCounter);
Assert.AreEqual("arg|arg", result);
Assert.AreEqual(1, di.Count);
// any introduction instance is invoked once only
((ICountingIntroduction)outerProxy).Inc();
Assert.AreEqual(1, countingMixin.Counter);
}