通过unget 安装Castle.Windsor

  

using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOP_Demo
{
	public class MyInterceptor : IInterceptor
	{

		public void Intercept(IInvocation invocation)
		{
			PreProceed(invocation);
			//如果是通过实现类创建的代理,才可以执行下面,也就是调用方法
			//invocation.Proceed();
			Console.WriteLine(invocation.Method.Name);
			PostProceed(invocation);
			//invocation.ReturnValue 给调用方法返回的值
			//invocation.Arguments 传进来的参数
		}
		public void PreProceed(IInvocation invocation)
		{
			Console.WriteLine("方法执行前");
		}

		public void PostProceed(IInvocation invocation)
		{
			Console.WriteLine("方法执行后");
		}
	}

	public class User
	{

		public string Name { get; set; }

		public string PassWord { get; set; }

	}
	public interface IUserProcessor
	{
		void RegUser(User user);
	}

	public class UserProcessor : IUserProcessor
	{
		public virtual void RegUser(User user)
		{
			Console.WriteLine("用户已注册。Name:{0},PassWord:{1}", user.Name, user.PassWord);
		}
	}
}

  

调用

using Castle.DynamicProxy;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOP_Demo
{
	class Program
	{
		static void Main(string[] args)
		{

			ProxyGenerator generator = new ProxyGenerator();
			MyInterceptor interceptor = new MyInterceptor();
			//通过实现类创建代理
			//UserProcessor userprocessor = generator.CreateClassProxy<UserProcessor>(interceptor);
			//通过接口 创建代理 自动生成实现接口类(操作il代码 .net emit)
			IUserProcessor userProcessor = generator.CreateInterfaceProxyWithoutTarget<IUserProcessor>(interceptor);

			User user = new User() { Name = "lee", PassWord = "123123123123" };
			userProcessor.RegUser(user);
			Console.ReadKey();
		}
	}
}

  

.net aop 操作 切面应用 Castle.Windsor框架 spring 可根据接口 自动生成一个空的实现接口的类的更多相关文章

  1. 多个IoC容器适配器设计及性能测试(Castle.Windsor Autofac Spring.Core)

    [转]多个IoC容器适配器设计及性能测试和容器选择 1. 采用的IoC容器和版本 Autofac.2.6.3.862 Castle.Windsor.3.1.0 Spring.Core.2.0.0 2. ...

  2. 文件参数化-utp框架之根据yaml文件自动生成python文件+utp运行用例

    根据yaml文件自动生成python文件 utp框架: bin目录:存放执行文件(run.py) cases目录:存放生成的用例的python文件(该目录下的文件为根据data目录下的测试用例生成的p ...

  3. spring-第十五篇之AOP面向切面编程之AspectJ框架简单应用

    1.去官方网站下载aspectj-1.8.0.jar 2.在jar包目录启动cmd,执行java -jar aspectj-1.8.0.jar,Next 3.检查JAVA_HOME路径是否正确,如果不 ...

  4. 使用T4模板为EF框架添加实体根据数据库自动生成字段注释的功能

    转自http://jeffblog.sinaapp.com/archives/501 首先我们先下载一个文件GetSummery,这里我提供了,大家可以直接下载:下载 我们在数据库建立一个表,并给表中 ...

  5. mybatis框架下使用generator插件自动生成domain/mapping/mapper

    手动去创建domain/mapping/mapper费时费力还容易出错,用插件自动生成非常的方便. 这里以MySQL数据库为例,也可以改成Oracle,改成相应的驱动和URL即可. 下载generat ...

  6. Aspects– iOS的AOP面向切面编程的库

    简介 一个简洁高效的用于使iOS支持AOP面向切面编程的库.它可以帮助你在不改变一个类或类实例的代码的前提下,有效更改类的行为.比iOS传统的 AOP方法,更加简单高效.支持在方法执行的前/后或替代原 ...

  7. AOP操作-准备工作

    AOP操作(准备) 1,Spring 框架中一般基于 AspectJ 实现AOP操作 (1)什么是 AspectJ *AspectJ 不是 Spring 组成部分,独立AOP框架,一般把 Aspect ...

  8. aop面向切面编程的实现

    aop主要用于日志记录,跟踪,优化和监控 下面是来自慕课网学习的一些案例,复制黏贴就完事了,注意类和方法的位置 pom添加依赖: <dependency> <groupId>o ...

  9. SSM 框架基于ORACLE集成TKMYBATIS 和GENERATOR自动生成代码(Github源码)

    基于前一个博客搭建的SSM框架 https://www.cnblogs.com/jiangyuqin/p/9870641.html 源码:https://github.com/JHeaven/ssm- ...

随机推荐

  1. LinuxMint(Ubuntu)安装文泉驿家族黑体字

    文泉驿黑体字家族在Ubuntu上很有用,可以解决系统字体发虚的问题. 通过下面的三条命令安装: sudo apt-get install ttf-wqy-microhei #文泉驿-微米黑 sudo ...

  2. Rabbitmq集群高可用

    转载:https://www.cnblogs.com/flat_peach/archive/2013/04/07/3004008.html RabbitMQ是用erlang开发的,集群非常方便,因为e ...

  3. 在Linux系统安装Nodejs 最简单步骤

    1.去官网下载和自己系统匹配的文件: 英文网址:https://nodejs.org/en/download/ 中文网址:http://nodejs.cn/download/ 通过  uname -a ...

  4. 好程序员web前端分享如何理解JS的单线程

    好程序员web前端分享如何理解JS单线程,JS本质是单线程的.也就是说,它并不能像JAVA语言那样,两个线程并发执行. 但我们平时看到的JS,分明是可以同时运作很多任务的,这又是怎么回事呢? 首先,J ...

  5. 在后台业务管理系统中使用Autofac实现微信接口的处理

    在后台业务管理系统中使用Autofac实现微信接口的处理,我们只需要把相关使用到的DLL放到BIN目录里面即可,通过IOC控制反转方式实现对接口的调用.在实现在业务系统里面,我们本身程序可能已经依赖了 ...

  6. ios 添加三方字体

    字体文件一般后缀名为.ttf 或.odf (备注: 有的字体是收费的,不能用于商业应用.所以还请设计师选择免费的字体好一点,不然会收到律师函哦) 1 加入字体文件 2. info.plist 文件引入 ...

  7. 初识Haskell 五:自定义数据类型和类型类

    对Discrete Mathematics Using a Computer的第一章Introduction to Haskell进行总结.环境Windows 自定义数据类型 data type de ...

  8. python3.4中自定义数组类(即重写数组类)

    '''自定义数组类,实现数组中数字之间的四则运算,内积运算,大小比较,数组元素访问修改及成员测试等功能''' class MyArray: '''保证输入值为数字元素(整型,浮点型,复数)''' de ...

  9. [wiki] Unix like

    1. Unix的发展历史 2. 纵向的图 3. 来源: https://zh.wikipedia.org/wiki/类Unix系统 4. 中文版   数种“类UNIX操作系统”的相互关系图 类Unix ...

  10. Linux(Ubunt)使用日记------常用软件汇总(不定时更新)

    整理总结日常Ubuntu中使用的一些软件,事实证明使用Linux真的会让人的欲望变小有个能用的就不错啦,不要调三捡四 解压类 Unzip | unzip -O CP936 files Unrar ra ...