- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
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 方法,则缓存不起作用。
谢谢你的帮助。
最佳答案
接口(interface)代理是通过包装代理目标对象创建的,因此对于接口(interface)这是不可能的。
您可以拦截对相同对象的调用,但仅限于类代理(前提是该方法是虚拟的)。查看类似 question 的答案.
您还可以尝试以不同的方式构建代码,将需要缓存的逻辑移动到无需使用其自身功能即可缓存的服务。
关于c# - 由另一个方法调用的方法上的 caSTLe windsor 拦截器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31262970/
我在调用 Resolve 时遇到异常: KernelException: Could not instantiate custom activator Inner Exception: {"Const
我的应用程序使用“SignalR”客户端/服务器通信框架。如果您不熟悉它,服务器端应用程序通常包含一个或多个“集线器”类(类似于 asmx 网络服务),每个类都提供可由客户端调用的方法。在启动期间,客
假设我有这样的组件 public class MyComponent { public MyComponent(string name) { } } 我基本上想让提供的构造函数
在 CaSTLe Windsor 场景中,我想检查我的容器是否注册了某个服务,并且基本上做 if (container.HasComponentFor()) { // resolve serv
我想知道是否有一些最佳实践来实现我需要的功能。 我有一个 Web 应用程序,它在启动期间通过反射扫描某些程序集(插件)并针对公共(public)内核注册它们的依赖项。 外部库可能需要相同的依赖项。 例
我想知道是否有一些最佳实践来实现我需要的功能。 我有一个 Web 应用程序,它在启动期间通过反射扫描某些程序集(插件)并针对公共(public)内核注册它们的依赖项。 外部库可能需要相同的依赖项。 例
是否有关于如何使用 CaSTLe Windsor 的自动事务管理的任何简单示例? documentation似乎缺少一些信息。我看到有用于 nHibernate、ActiveRecord 等的工具……
考虑这个例子: public class Factory { private List subFactories; public Factory(Lis
我正在将我们的项目从 .Net 2 升级到 .Net4.5,同时我将尽可能多的引用推送到 NuGet 并确保版本是最新的。 我在运行其中一项测试时遇到问题 测试类: public cl
当我开始使用 Windsor 时,我认为 DI 会很简单。现在它让我越来越困惑。 在我看来,存储库是一个具有单例生命周期的类。我应该有一个 FooRepository 实例来在应用程序的生命周期内将
我有一个接口(interface) ISession,其实例由不同的 session 工厂生成,具体取决于类所属的命名空间。 我的组件注册示例: IWindsorContainer container
我有一个看似简单的用例。有一个 ICsvReader 组件。让我们在这里简单地将它命名为 Reader。我们加载了一组已知的 CSV 文件,其中一些有标题,有些没有。目前有多个阅读器:Reader_S
这是我在 Global.asax 中的代码 WindsorContainer container = new WindsorContainer(); container.Register(Compo
在使用 ArrayResolver 时,如果我注册了一个接口(interface)的多个实现和一个依赖于所述接口(interface)数组的类,我希望数组解析器注入(inject)所有可以成功解析的接
有没有人有一些使用城堡 Windsor InstallerFactory 来订购安装程序的示例代码? 似乎无法在文档或其他地方找到它。 干杯 最佳答案 您只能使用 InstallerFactory与
documentation 中有说明你应该总是让拦截器 transient 。如果我有这个示例代码; //register interceptor container.Register(Classes
我有一点问题。我在 CaSTLe Windsor IOC Container 工作。现在我想做的只是弄乱一些 AOP 原则,而我特别想做的是基于方法名称执行一些日志记录。我一直在研究拦截器,目前我正在
有人对使用 CaSTLe DynamicProxy 拦截属性的更好方法有什么建议吗? 具体来说,我需要我正在拦截的 PropertyInfo,但它不是直接在 IInvocation 上,所以我要做的是
使用 ArrayResolver 时,如果我注册了多个实现相同接口(interface)的依赖项,并且我已经注册了依赖于这些依赖项数组的类,那么人们会期望 ServiceOverrides 受到尊重并
如何使用 Windsor 容器将 appSettings 条目的值(来自 app.config 或 web.config)注入(inject)服务?如果我想将 Windsor 属性的值注入(injec
我是一名优秀的程序员,十分优秀!