Unity:拦截(AOP)拦截属性?还拦截表单(winform)上的方法?

发布于 2024-11-04 01:53:03 字数 783 浏览 2 评论 0原文

我很想知道是否可以拦截属性和方法?我找到了一个很好的例子,似乎支持拦截方法,是否也可以拦截属性以及事件呢?

我想为我的应用程序编写一个 AOP 日志系统。

这是示例: http://codetheorist.com/2011/04/interception-made -easy/

我尝试了一下并设法让它在类库上工作,

如果我想让它在 WinForms 上工作怎么办?我还需要从容器中解析表单,实际上表单是一个类,但我无法让它工作。

有人有任何想法,或者已经做到了吗?

我确实注意到 Aurum,它是 Unity 之上的框架,但我想如果可能的话我更愿意使用 Unity 扩展。

编辑

这是我为我的winforms尝试过的......但它不起作用,它在program.cs中

var form = UnityContainer.Container.Resolve<frmMain>();

///Application.Run(new frmMain());  // OLD

Application.Run(form);  // new using the resolved from unity.. It resolves it and i registered it ... 

i am very interested in finding out if its possible to intercept Properties as well as Methods? I found a great example and seems to support intercepting Methods, would it also be possible to intercept Properties and what about events??

I would like to write a AOP logging system for my app.

here is the example: http://codetheorist.com/2011/04/interception-made-easy/

I gave it a try and managed to get it to work on a class library,

what if i would like to get it to work on WinForms? I need to also resolve the Form from the container, a form in reality is a class but i couldn't get it to work.

Anyone have any ideas, or has already done it?

I did notice Aurum which is framework on top of Unity but i think i would prefer to use the Unity extensions if at all possible.

EDIT

This is what i tried for my winforms.... but it didn't work, its in program.cs

var form = UnityContainer.Container.Resolve<frmMain>();

///Application.Run(new frmMain());  // OLD

Application.Run(form);  // new using the resolved from unity.. It resolves it and i registered it ... 

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

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

发布评论

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

评论(1

烟酉 2024-11-11 01:53:03

属性只是带有一些附加元数据的方法,因此如果该属性是虚拟的或接口的一部分,则它可以被拦截 - 就像任何其他虚拟方法一样。

A property is just a method with some additional metadata, so if the property is virtual or part of an interface it can be intercepted - just like any other virtual method.

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