通过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. centos7 安装 pyspider 出现的一系列问题及解决方案集合

    先安装python3 和 pip3 wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz 安装zlib-devel包(后面安装pi ...

  2. “Axure”介绍

    一. Axure RP简介: Axure RP 能帮助网站需求设计者,快捷而简便的创建基于网站构架图的带注释页面示意图.操作流程图.以及交互设计,并可自动生成用于演示的网页文件和规格文件,以提供演示与 ...

  3. 简单解析nestJS目录

    使用Nest CLI设置新项目非常简单 .只需确保 安装了npm,然后在OS终端中使用以下命令: $ npm i -g @nestjs/cli $ nest new project-name $ cd ...

  4. int float double 最小值与最大值

    #include <iostream> #include <limits> using namespace std; int main() { cout << &q ...

  5. CodeForces 1151E Number of Components

    题目链接:http://codeforces.com/problemset/problem/1151/E 题目大意: n个人排成一个序列,标号为 1~n,第 i 个人的学习成绩为 ai,现在要选出学习 ...

  6. WebSocket原理

    一 . WebSocket原理 1.1.背景 WebSocket 是基于Http 协议的改进,Http 为无状态协议,基于短连接,需要频繁的发起请求,第二 Http 只能客户端发起请求,服务端无法主动 ...

  7. java &与&& |与||的区别

    一.与操作和或操作的区别 (1)在Java程序中,使用与操作,要求所有表达式的判断结果都是TRUE,才为真,若有一个为FALSE,那么最终判断结果则为FALSE (2)使用或操作,只要其中有一个表达式 ...

  8. [NOI 2018] 归程

    Description 传送门 Solution 65分做法 先求出每个点到\(1\)号点的最短路,记为\(d[i]\).然后按照海拔从大到小依次加边,并查集维护每个连通块中\(d[i]\)的最小值, ...

  9. 【CERC2016】【BZOJ4792】村庄 搜索

    题目大意 有一个 \(2^n\times 2^n\) 的网格,左下角坐标为 \((0,0)\),右上角坐标为 \((2^n,2^n)\). 定义格点 \((x,y)\) 为坐标系中坐标为 \((x,y ...

  10. ios端position为fixed失效的解决办法

    关键代码 document.getElementById("searchInputbox").addEventListener('touchmove', handler, {pas ...