个人习惯在类中实现接口统一用显式实现, 没想到今天因为这个习惯浪费了一整天的时间, 差点就要砸键盘了
[ConfigurationElementType(typeof(CustomCallHandlerData))]
public class MyAuthCallHandler : ICallHandler
{
private int order = 0;
public MyAuthCallHandler()
{
}
public MyAuthCallHandler(NameValueCollection attributes)
{
}
IMethodReturn ICallHandler.Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.WriteLine("icallhandler.invoke| " + input.MethodBase.DeclaringType.FullName + "::" + input.MethodBase.Name);
return getNext()(input, getNext);
}
int ICallHandler.Order
{
get
{
return order;
}
set
{
order = value;
}
}
}
就这么简单的一个玩意, 用Attribute应用到Method一切正常
[AttributeUsage(AttributeTargets.Method)]
public class MyAuthCallHandlerAttribute : HandlerAttribute
{
public override ICallHandler CreateHandler(Microsoft.Practices.Unity.IUnityContainer container)
{
return new MyAuthCallHandler();
}
}
当我想用config文件进行配置的时候, 恶梦来了, 实例化对象的时候死活说参数为null, 一开始以为是CustomCallHandlerData的问题,找了半天资料
最后一个个排除, 原来居然是CallHandler的接口显式实现的问题, 悲剧~~
改成:
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
public int Order
一切正常了, 莫名其妙 :(