Unity:拦截(AOP)拦截属性?还拦截表单(winform)上的方法?
我很想知道是否可以拦截属性和方法?我找到了一个很好的例子,似乎支持拦截方法,是否也可以拦截属性以及事件呢?
我想为我的应用程序编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
属性只是带有一些附加元数据的方法,因此如果该属性是虚拟的或接口的一部分,则它可以被拦截 - 就像任何其他虚拟方法一样。
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.