通过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. 搭建Hadoop的环境

    准备实验的环境: 1.安装Linux.JDK 2.配置主机名.免密码登录 3.约定:安装目录:/usr/local/bin 安装: 1.解压 : tar -zxvf hadoop-2.7.7.tar. ...

  2. 【spring源码分析】IOC容器初始化(四)

    前言:在[spring源码分析]IOC容器初始化(三)中已经分析了BeanDefinition注册之前的一些准备工作,下面将进入BeanDefinition注册的核心流程. //DefaultBean ...

  3. pytest生成测试报告-4种方法

    1.生成resultlog文件 2.生成JunitXML文件 3.生成html测试报告 > pip install pytest-html     # 通过pip安装pytest-html 4. ...

  4. AtCoder Grand Contest 032 A - Limited Insertion( 思维)

    Time Limit: 2 sec / Memory Limit: 1024 MB Score : 400400 points Problem Statement Snuke has an empty ...

  5. 安装maven,并配置eclipse

    平台 ubuntu 18.04 + Java 8 下载并安装Maven 下载页面:http://maven.apache.org/download.cgi 我这里使用写博客是最新的版本3.6.1,选择 ...

  6. (二)jdk8学习心得之Lambda表达式

    二.Lambda表达式 1. 格式 (参数1,参数2,…,参数n)->{方法体} 注意: (参数1,参数2,...,参数n)要与方法接口中的参数一致,但是名字可以不一样. 此外,方法类型接口,有 ...

  7. Linux centos nginx下载安装初步

    下载源码包解压编译 1.下载 # wget http://nginx.org/download/nginx-1.9.9.tar.gz 2.解压 # tar xvf nginx-1.9.9.tar.gz ...

  8. redis 连接idea一直被拒绝

    网上查找的方法 方法一:idea中已经下载了Iedis 插件, 也导入了jar包 <!-- https://mvnrepository.com/artifact/commons-pool/com ...

  9. codeforces510D

    Fox And Jumping CodeForces - 510D Fox Ciel is playing a game. In this game there is an infinite long ...

  10. mac 重装系统

    Mac打算送人,现在退出自己的帐号恢复出厂设置. 协助工具下载:链接:https://pan.baidu.com/s/1vHt-Mk4otawEGidyz_WW2g 提取码:9ax6 用transma ...