第一次执行的时候没有问题。
当我执行缓存对象的时候,就报了个类型转换错误。
也就是说容器并没有返回我要的对象,而是直接返回了个TransparentProxyMethodReturn对象。
google一圈没找到结果,请同行赐教。
public class CacheHandler : ICallHandler
{
/// <summary>
/// 缓存key
/// </summary>
public string Key { get; set; }
public int Order { get; set; }
private static volatile System.Web.Caching.Cache _webCache = System.Web.HttpRuntime.Cache;
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
object obj = _webCache.Get(Key);
if (obj != null)
return input.CreateMethodReturn(obj, input.Arguments);
var result = getNext().Invoke(input, getNext);
_webCache.Insert(Key, result);
return result;
}
}
demo 在这里
http://files.cnblogs.com/yuanhuaming/UnityAop.rar
return input.CreateMethodReturn(obj, input.Arguments);
改成 return obj as IMethodReturn;