Unity перехват не работает, как ожидалось
Я использую единство в качестве моей основы, но она не работает, как ожидалось. Пожалуйста, проверьте мой код ниже.
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
Я хочу, чтобы журнал выполнялся только при явном вызове метода. как это предотвратить?