0

Unity を aop フレームワークとして使用していますが、期待どおりに動作しません。以下のコードを確認してください。

container.RegisterType<IPerson, Person>(new Interceptor<TransparentProxyInterceptor>(),
    new InterceptionBehavior<LoggingInterceptionBehavior>(), 
    new InjectionConstructor(container.Resolve<IPlay>(), container.Resolve<IEat>()));

var person = container.Resolve<IPerson>();
person.Play();
person.Eat();
((IAnimal)person).Sleep();
Console.Read();

public IMethodReturn Invoke(IMethodInvocation input,
       GetNextInterceptionBehaviorDelegate getNext)
{
    Console.WriteLine(string.Format("Invoking method {0} begin", input.MethodBase));
    var result = getNext()(input, getNext);
    if (result.Exception != null)
    {
        Console.WriteLine("{0} throws exception", input.MethodBase);
    }
    else
    {
        Console.WriteLine(string.Format("Invoking method {0} end", input.MethodBase));
    }
    return result;
}

container.Resolve() と ((IAnimal)person) が実行されると、動作も実行され、出力されます

メソッド System.Type GetType() begin の呼び出し

メソッド System.Type GetType() end の呼び出し

メソッドを明示的に呼び出したときにのみログを実行したい。それを防ぐ方法は?

4

0 に答える 0