博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring.net aop 讲解
阅读量:7088 次
发布时间:2019-06-28

本文共 1688 字,大约阅读时间需要 5 分钟。

spring.net aop几个术语:

切面:针对类

切点:针对方法

object.xml

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace TestAop{    public class Advisor : AopAlliance.Intercept.IMethodInterceptor    {                public object Invoke(AopAlliance.Intercept.IMethodInvocation invocation)        {            NewUser newUser = new NewUser();            newUser.BeforeWhoami();            var result = invocation.Proceed();            newUser.AfterWhoami();            return result;        }    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace TestAop{    public class NewUser    {        public void BeforeWhoami()        {            Console.WriteLine("I am before");        }        public void AfterWhoami()        {            Console.WriteLine("I am after");        }    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace TestAop{    public interface  IUser    {        void Whoami();    }    public class User:IUser    {        public void Whoami()        {            Console.WriteLine("I am zhangwei");        }    }}
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace TestAop{    class Program    {        static void Main(string[] args)        {            Spring.Context.IApplicationContext context               = new Spring.Context.Support.XmlApplicationContext("objects.xml");            IUser user = context.GetObject("user") as IUser;            user.Whoami();            Console.ReadKey();        }    }}

运行:

转载地址:http://ehyql.baihongyu.com/

你可能感兴趣的文章
盛极而衰,互联网体育是伪风口还是真趋势?
查看>>
14-《ARKit by Tutorials》读书笔记1:开始入门
查看>>
[MetalKit]33-Ambient-Occlusion-in-Metal环境光遮蔽
查看>>
图解JavaScript算法排序
查看>>
Flask环境搭建(自己学习用)
查看>>
iOS逆向之旅(进阶篇) — HOOK(Method Swizzling)
查看>>
Javascript之正则表达式的学习笔记
查看>>
Hadoop 学习系列(三)之 YARN 详细解析
查看>>
QPM 之悬浮窗助力性能优化
查看>>
YYCache 源码学习(一):YYMemoryCache
查看>>
ios 原生骨架动画库
查看>>
前端性能优化常用总结
查看>>
flutter安装开发环境-问题记录
查看>>
第十四课时: 登录/登出以及JWT认证
查看>>
渲染机制/页面性能/错误监控
查看>>
Dom中高big 事件总结(持续更新中)
查看>>
Immutable.js 源码解析 --List 类型
查看>>
【修真院“善良”系列之十六】代码结构中Dao,Service,Controller,Util,Model是什么意思,为什么划分...
查看>>
js数据结构-栈
查看>>
前端构建_webpack
查看>>