1
即时通讯使用统一,我喜欢使用InterceptionBehavior进行日志记录。当我将InterceptionBehavior添加到类型regestration时,什么都不会发生,并且不会调用InterceptionBehavior。统一拦截行为不会被调用
这里是行为类:
public class Logger : IInterceptionBehavior
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
Console.WriteLine("Methode {0} wurde aufgerufen",input.MethodBase.Name);
return getNext.Invoke().Invoke(input, getNext);
}
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public bool WillExecute => true;
}
而且注册类型:
container.RegisterType<IParser, Parser>(
new Interceptor(new InterfaceInterceptor()),
new InterceptionBehavior(new Logger()));
container.RegisterType<IBerechne, Berechne>(
new Interceptor(new InterfaceInterceptor()),
new InterceptionBehavior(new Logger()));
您可以查看您的问题和接受帮助的答案,这可能会让更多的人有兴趣回答你。 – Jcl