温莎的问题呼吁“通用化” 添加拦截器后的方法

发布于 2024-07-30 11:06:06 字数 936 浏览 3 评论 0原文

我有一个运行良好的应用程序,它使用 Windsor 进行 IoC。 我想记录对 Windsor 实例化的组件进行的所有调用的方法调用、参数和执行时间,因此我实现了一个实现 IInterceptor 的 LoggingInterceptor,其中包含:

Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
invocation.Proceed();  // EXCEPTION IS THROWN HERE
sw.Stop();
Logger.Debug(.....

现在,之前运行良好的操作将抛出 VerificationExceptions,并显示以下消息:

Method Repositories.RepositoryBase.GetAll:类型参数“ET”违反了类型参数“ET”的约束。

该方法的签名是:(

public IList<ET> GetAll<ET>() where ET : EntityBase2, IEntity2  

其中 EntityBase2 和 IEntity2 来自 LLBLGenPro)

该方法的调用者如下:(

public IList<ServerEntity> GetServers()
{
   return GetRepository<IServerRepository>().GetAll<ServerEntity>();
}

其中 GetRepository<>() 只是 ServiceLocator 的包装)

如果我从城堡配置中注释掉拦截器,一切又恢复正常了。

为什么现在会发生这种情况?是否有解决办法,以便我可以使用我的日志拦截器?

谢谢

I have an application that was working fine that uses Windsor for IoC. I want to log the method calls, parameters, and execution time of all calls made to components instantiated by Windsor, so I implemented a LoggingInterceptor that implements IInterceptor, that contains:

Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
invocation.Proceed();  // EXCEPTION IS THROWN HERE
sw.Stop();
Logger.Debug(.....

Now operations that previously worked fine are throwing VerificationExceptions with the following message:

Method Repositories.RepositoryBase.GetAll: type argument 'ET' violates the constraint of type parameter 'ET'.

The signature of the method is:

public IList<ET> GetAll<ET>() where ET : EntityBase2, IEntity2  

(where EntityBase2 and IEntity2 are from LLBLGenPro)

The caller of the method is as follows:

public IList<ServerEntity> GetServers()
{
   return GetRepository<IServerRepository>().GetAll<ServerEntity>();
}

(where GetRepository<>() is just a wrapper around ServiceLocator)

If I comment out the interceptor from the castle configuration, it all works fine again.

Why is this happening now, and is there a fix so I can use my logging interceptor?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风月客 2024-08-06 11:06:06

如果您使用旧版本的 Windsor(RC3 或更早版本),我认为它不支持泛型类型的拦截器,因为旧的 DynamicProxy 不支持它。

您可以尝试更新到 Windsor 的最新版本。 它在底层使用 DynamicProxy2,它适用于泛型类型。

If you're using an older version of Windsor (RC3 or earlier), I don't think it supports interceptors on Generic types because the old DynamicProxy doesn't support it.

You might try updating to the latest release of Windsor. It uses DynamicProxy2 under the hood, which works with generic types.

对你的占有欲 2024-08-06 11:06:06

这只发生在 Visual Studio 调试器下吗?

最新的 Castle 主干版本也会出现这种情况吗? (您可以此处找到)

Does this happen only under Visual Studio debugger?

Does this happen on the latest trunk version of Castle as well? (which you can find here)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文