【发布时间】:2015-09-24 14:39:15
【问题描述】:
拦截器
public class CachingInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
// code comes here....
}
}
业务层
public class Business : IBusiness
{
public void Add(string a)
{
var t= GetAll();
// code comes here....
}
[CacheAttribute]
public string GetAll()
{
// code comes here....
}
}
类
public class JustForTest
{
public JustForTest(IBusiness business)
{
//if GetAll is invoked directly caching works fine.
business.GetAll();
//if GetAll is invoked over Add method caching doesn't work.
business.Add();
}
}
add 方法调用 GetAll 方法。如果我直接调用 GetAll 方法,缓存会起作用。如果 Add 方法调用 GetAll 方法,缓存不起作用。
感谢您的帮助。
【问题讨论】:
-
您应该从
container中解析Business实例,而不是自己解决new。 -
谢谢你。其实我做到了。我只是想让代码简单。我使用安装程序来实现。
标签: c# castle-windsor aop interceptor aspect