.Net AOP(二)远程代理Remoting/RealProxy
来源:互联网 发布:淘宝评论怎么没有了 编辑:程序博客网 时间:2024/05/21 19:26
远程代理
1、使用.Net Remoting/RealProxy
采用TransparentProxy和RealProxy实现对象的代理,实现思路如下:Client -TransparentProxy - RealProxy - Target Object
下面实现自定义的TransparentProxy和RealProxy
using System.Runtime.Remoting.Proxies;using System.Runtime.Remoting.Messaging; //RealProxy public class MyRealProxy<T>:RealProxy { private T _target; public MyRealProxy(T target) : base(typeof(T)) { this._target = target; } public override IMessage Invoke(IMessage msg) { PreProceede(msg); IMethodCallMessage callMessage = (IMethodCallMessage)msg; object returnValue = callMessage.MethodBase.Invoke(this._target, callMessage.Args); PostProceede(msg); return new ReturnMessage(returnValue, new object[0], 0, null, callMessage); } public void PreProceede(IMessage msg) { Console.WriteLine("方法执行前"); } public void PostProceede(IMessage msg) { Console.WriteLine("方法执行后"); } } //TransparentProxy public static class TransparentProxy { public static T Create<T>() { T instance = Activator.CreateInstance<T>(); MyRealProxy<T> realProxy = new MyRealProxy<T>(instance); T transparentProxy = (T)realProxy.GetTransparentProxy(); return transparentProxy; } }
用户注册接口和实现
public interface IUserProcessor { void RegUser(User user); } public class UserProcessor : MarshalByRefObject, IUserProcessor { public void RegUser(User user) { Console.WriteLine("用户已注册。"); } }
客户端调用
public class Client { public static void Run() { try { User user = new User() { Name = "lee", PassWord = "123123123123" }; UserProcessor userprocessor = TransparentProxy.Create<UserProcessor>(); userprocessor.RegUser(user); } catch (Exception ex) { throw ex; } } }
优点:简单实现
缺点:性能差
0 0
- .Net AOP(二)远程代理Remoting/RealProxy
- .Net AOP(二)远程代理Remoting/RealProxy
- .net core 2.0学习笔记(六):Remoting核心类库RealProxy迁移
- .Net基于Remoting远程调用实现的AOP拦截
- 继上次使用remoting实现了AOP,这次是通过RealProxy和ProxyAttribute实现
- .Net Remoting基础(二)
- [Remoting] 二:远程对象
- [Remoting] 二:远程对象
- .NET Romoting 学习总结(二)—— Remoting技术之远程调用三步走
- 微软的远程处理框架.NET Remoting(转天极网)之二
- AOP through .Net Remoting Infrastructure
- Aop RealProxy 千年遇BUG
- Remoting核心类库RealProxy迁移
- Microsoft .NET Remoting:技术概述(二)
- 利用消息机制实现.NET AOP(面向方面编程)--通过RealProxy实现 zz
- 利用消息机制实现.NET AOP(面向方面编程)--通过RealProxy实现
- .NET远程处理(Remoting)与WCF的性能对比
- AOP之代理模式(二)
- Linux内核分析:实验五
- Android drawPath实现QQ拖拽泡泡
- Tuhdo emacs 学习笔记
- windows内核驱动内存管理之Lookaside使用
- 一周乱弹(3.27 )1,copyProperties 比较2, java Object... objects 可变参数
- .Net AOP(二)远程代理Remoting/RealProxy
- 数字反演
- Android开发:按一定频率同时获取多个传感器数据
- BZOJ 1997 HNOI 2010 Planar 2-SAT
- 在c代码中使用logcat
- C++ 利于宏模拟C#的正则表达式
- HDU 1059 Dividing(多重背包)
- Android中序列化的实现?使用Serializable还是Parcelable
- 数学归纳法初探