城堡动态代理创建
我正在实现一种设计,其中我的层位于客户端和服务器之间,无论我从服务器获得什么对象,我都会将其包装在透明代理中并提供给客户端,这样我就可以跟踪对象中发生的更改,所以当保存回来时,我只会发送更改的信息。
我查看了castle动态代理,linfu,虽然它们可以生成代理类型,但它们不能获取现有对象并包装它们。
想知道是否可以使用这些框架,或者是否有任何其他框架可以实现这一点......
I am implementing a design where my layer would sit between client and server, and whatever objects i get from server, i would wrap it in a transparent proxy and give to the client, that way i can keep a track of what changed in the object, so when saving it back, i would only send changed information.
I looked at castle dynamic proxy, linfu, although they can generate a proxy type, but they cant take existing objects and wrap them instead.
Wondering if its possible to do with these frameworks, or if there any other frameworks that enable this...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们使用无状态实体,并且由于 ASP.NET GridView 的行为,我需要创建一个仅包装现有对象的代理。
我创建了一个拦截器,它以这种方式保留目标实例:
然后您可以简单地创建包装代理:
We use stateless entities, and due to a behaviour of ASP.NET GridView I needed to create a proxy which would only wrap existing object.
I created an interceptor which keeps a target instance this way:
Then you can simply create the wrapper proxy:
Castle Dynamic Proxy 3.x 或更高版本可以做到这一点,但您必须记住它只能拦截虚拟方法,因此它不是一个完美的抽象。
Castle Dynamic Proxy 3.x or later can do that, although you have to keep in mind that it can only intercept virtual methods so it's not a perfect abstraction.