Wie verwende ich IInterceptor in Castle.DynamicProxy?
Ich habe ein Beispiel wie dieses geschrieben
Simple Calculator Klasse:
public class Calculator
{
public int Add(int a, int b)
{
return a + b;
}
}
implementierter "IInterceptor" von DynamicProxy
[Serializable]
public abstract class Interceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
ExecuteBefore(invocation);
invocation.Proceed();
ExecuteAfter(invocation);
}
protected abstract void ExecuteAfter(IInvocation invocation);
protected abstract void ExecuteBefore(IInvocation invocation);
}
Erstellte eine Interceptor-Klasse und erbte sie von der "Interceptor" -Klasse
public class CalculatorInterceptor : Interceptor
{
protected override void ExecuteBefore(Castle.DynamicProxy.IInvocation invocation)
{
Console.WriteLine("Start");
}
protected override void ExecuteAfter(Castle.DynamicProxy.IInvocation invocation)
{
Console.WriteLine("End");
}
}
aber als ich es benutzt habe funktioniert es NICHT !!!
static void Main(string[] args)
{
ProxyGenerator generator = new ProxyGenerator();
Calculator c = generator.CreateClassProxy<Calculator>(new CalculatorInterceptor());
var r = c.Add(11, 22);
Console.WriteLine(r);
Console.ReadKey();
}
Ich sehe nur so etwas:
START
33
END
aber nur anzeigen
33
Wie kann ich das korrigieren?!