Lind.DDD.LindAspects方法拦截的介绍
什么是LindAspects
之前写了关于Aspects的文章《Lind.DDD.Aspects通过Plugins实现方法的动态拦截~Lind里的AOP》,今天主要在设计思想上进行刨析一下,对缓存拦截器一直没有实现,所以文章了也一直没有发出来,让大家等这么久实在不好意思。LindAspects主要是面向切面编程AOP的一种实现,就像MVC框架里的Filter,Filter会自己注入到了每个Action执行的各个环节里,而我们可以直接实现自己的Filter即可,例如只要是继承ActionFilter,那么你的Filter在Action执行时就可以被动态执行,这种设计就相当于把整个Action横切开来,注入我们需要的代码,这大概念就是面向切面(方面)编程的真谛吧!
LindAspects原理是什么
主要通过Emit实现对方法的重写,这个方法不向Unity.Interception非要是虚方法,咱们的Emit本质上是建立一个新的类型,然后建立一个新的方法,这个方法里再去执行当前被拦截的方法的主体,然后通过主体方法实现的AspectAttribute来控制是在主体执行前注入还是在主体执行之后注入!
配合LindPlugins实现对象的生产
方法的对象如何生产一直是个问题,传统方法是通过IoC去创建对象,而你使用new去生产对象一定是不行的,因为你的拦截器无法注入到实例上,在Lind环境里,一切组件都应该是“插件(LindPlugins)”,它们的注册和生产也是统一的,都是通过LindPlugins来实现,当前再往底层看,Plugins本身也是通过autofac这个ioc容器实现的,呵呵。
两种生产拦截对象的对比
Aspects本身的工厂生产
[TestMethod]
public void TestMethod1()
{
ITest test = ProxyFactory.CreateProxy(typeof(ITest), typeof(LoggerAspectAttribute)) as ITest;
test.Do();
}
LindPlugins的容器生产
[TestMethod]
public void AspectCachingGet()
{
var old = PluginManager.Resolve<IAopHelloTest2>();
var result = old.GetData("zz", );
Console.WriteLine(result);
}
LindAspects设计图
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAApUAAAE6CAIAAADIkT5WAAAgAElEQVR4nO2d61dT1773z58y/47dPcah73RsPQNKztjjVPfYT1sr2FYwENRasV4aBKl4w6AVIgS5KRIuEYI31KAkAUISsRavFSMEA7p7qj3dunfn82LlsrKykqwVVrIu+X7GZ3QsZuaac66Zn/NrUmv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an+w85/vqtGsu8Es26hV1CFOY+zoEQEZE5zfDdd/igR5fcc0YhGwrWyaH3M9z9geFUIeQ1xzXIQCykGF+AwAAAEBGkN8AAACA+kB+AwAAAOoD+Q0AAACoD+Q3AAAAoD6Q3wAAAID6QH4DAAAA6gP5DQAAAKgP5DcAAACgPv4/+NTUe2C73HQAAAAASUVORK5CYII=" alt="" />
CachingAspectAttribute在介绍
数据缓存这个东西经常被我们提到,现在很多产品都是异步缓存,就是先生成缓存数据,然后在方法里直接从缓存取即可,而今天大叔说的CachingAspectAttribute是指在方法中进行拦截,缓存添加与读取的动作完成由特性拦截器去做,这样做的好处是把业务逻辑与缓存逻辑分开,解耦你的代码!
/// <summary>
/// 有返回值的方法拦截动作
/// </summary>
/// <param name="context"></param>
public override object FuncInvoke(InvokeContext context, MethodInfo methodInfo)
{
var paramList = InitParams(context, methodInfo);
var obj = Activator.CreateInstance(methodInfo.ReflectedType);
switch (cachingMethod)
{
case CachingMethod.Get:
#region 读缓存
//redis键名,在put和get时使用
var key = prefix + context.Method.MethodName;
//hashset键名,参数组合
var param = string.Join("_", context.Parameters.Select(i => i.Para));
if (!RedisClient.RedisManager.Instance.GetDatabase().KeyExists(key))
{
var objValue = methodInfo.Invoke(obj, paramList.ToArray());
RedisClient.RedisManager.Instance.GetDatabase().HashSet(key, param, Lind.DDD.Utils.SerializeMemoryHelper.SerializeToJson(objValue));
return objValue;
}
var entity = RedisClient.RedisManager.Instance.GetDatabase().HashGet(key, param);
return Lind.DDD.Utils.SerializeMemoryHelper.DeserializeFromJson<object>(entity.ToString());
#endregion
case CachingMethod.Remove:
case CachingMethod.Put:
#region 缓存失效
var putvalue = methodInfo.Invoke(obj, paramList.ToArray());
RemoveCache(methodInfo);
return putvalue;
#endregion
default:
throw new InvalidOperationException("无效的缓存方式。");
}
}
本缓存特性主要使用redis实现持久化,在key的设计上使用了前缀在方法名及方法参数的规则,存储结构如hashset,在缓存失效上使用了方法的动态触发,我们可以看到,代码中定义了缓存的方式,读,加,移除等,我们可以在具体方法上控制缓存的类型,下面是具体方法的特性注入,代码如下:
public class AopHello : IAopHelloTest2
{
#region IHello 成员
[CachingAspect(CachingMethod.Get)]
public List<DtoUser> GetData(string title, int age)
{
//读取数据的业务代码
return new Test_Code_FirstEntities().WebManageUsers.Select(i => new DtoUser
{
Id = i.ID,
Name = i.LoginName
}).ToList(); } [CachingAspect(CachingMethod.Remove, "GetData")]
public void AddData(string title)
{
//添加数据的业务代码...
} #endregion
}
从代码中可以看到,业务代码如负责自己的业务,缓存注入只是一个特性标记!这才是大叔希望看到的缓存注入点!
感谢各位的阅读,希望文章给大家一些启发!
Lind.DDD.LindAspects方法拦截的介绍的更多相关文章
- Lind.DDD敏捷领域驱动框架~介绍
回到占占推荐博客索引 最近觉得自己的框架过于复杂,在实现开发使用中有些不爽,自己的朋友们也经常和我说,框架太麻烦了,要引用的类库太多:之前架构之所以这样设计,完全出于对职责分离和代码附复用的考虑,主要 ...
- Lind.DDD.Caching分布式数据集缓存介绍
回到目录 戏说当年 大叔原创的分布式数据集缓存在之前的企业级框架里介绍过,大家可以关注<我心中的核心组件(可插拔的AOP)~第二回 缓存拦截器>,而今天主要对Lind.DDD.Cachin ...
- Lind.DDD.Messaging框架通讯组件介绍
回到目录 大 家好,今天有时间来介绍一下Lind.DDD框架里的消息机制,消息发送这块一般的实现方法是将Email,SMS等集成到一个公用类库里,而本身 Email和SMS没什么关系,它们也不会有什么 ...
- Lind.DDD.UoW~方法回调完成原子化操作
回到目录 本文来自于实践中的不足 在最近开始过程中,遇到了一个问题,之前设计的工作单元UoW只支持Insert,Update,Delete三种操作,即开发人员可以将以上三种操作同时扔进工作单元,由工作 ...
- Lind.DDD.Aspects通过Plugins实现方法的动态拦截~Lind里的AOP
回到目录 .Net MVC之所以发展的如些之好,一个很重要原因就是它公开了一组AOP的过滤器,即使用这些过滤器可以方便的拦截controller里的action,并注入我们自己的代码逻辑,向全局的异常 ...
- Lind.DDD.Domain领域模型介绍
回到目录 Lind.DDD.Domain位于Lind.DDD核心项目中,它主要面向领域实体而设计,由一个IEntity的标识接口,EntityBase基类和N个Entity实体类组成,其中IEntit ...
- Lind.DDD.Repositories.EF层介绍
回到目录 Lind.DDD.Repositories.EF以下简称Repositories.EF,之所以把它从Lind.DDD中拿出来,完全出于可插拔的考虑,让大家都能休会到IoC的魅力,用到哪种方法 ...
- Lind.DDD.Repositories.Redis层介绍
回到目录 之前已经发生了 大叔之前介绍过关于redis的文章,有缓存,队列,分布式pub/sub,数据集缓存以及仓储redis的实现等等,而今天在Lind.DDD的持久化组件里,redis当然也有一席 ...
- Lind.DDD.Authorization用户授权介绍
回到目录 Lind.DDD.Authorization是Lind.DDD框架的组成部分,之所以把它封装到框架里,原因就是它的通用性,几乎在任何一个系统中,都少不了用户授权功能,用户授权对于任何一个系统 ...
随机推荐
- 【小程序分享篇 一 】开发了个JAVA小程序, 用于清除内存卡或者U盘里的垃圾文件非常有用
有一种场景, 手机内存卡空间被用光了,但又不知道哪个文件占用了太大,一个个文件夹去找又太麻烦,所以我开发了个小程序把手机所有文件(包括路径下所有层次子文件夹下的文件)进行一个排序,这样你就可以找出哪个 ...
- vue2.0实践的一些细节
最近用vue2.0做了个活动.做完了回头发现,好像并没有太多的技术难点,而自己好像又做了比较久...只能说效率有待提升啊...简单总结了一些比较细节的点. 1.对于一些已知肯定会有数据的模块,先用一个 ...
- 在.NET Core 里使用 BouncyCastle 的DES加密算法
.NET Core上面的DES等加密算法要等到1.2 才支持,我们可是急需这个算法的支持,文章<使用 JavaScriptService 在.NET Core 里实现DES加密算法>需要用 ...
- 10个最好用的HTML/CSS 工具、插件和资料库
大家在使用HTML/CSS开发项目的过程中,有使用过哪些工具,插件和库?下面介绍的10种HTML/CSS工具,插件和资料库,是国外程序员经常用到的. Firebug Lite FirebugLite ...
- 实现代理设置proxy
用户在哪些情况下是需要设置网络代理呢? 1. 内网上不了外网,需要连接能上外网的内网电脑做代理,就能上外网:多个电脑共享上外网,就要用代理: 2.有些网页被封,通过国外的代理就能看到这被封的网站:3. ...
- MySQL数据库和InnoDB存储引擎文件
参数文件 当MySQL示例启动时,数据库会先去读一个配置参数文件,用来寻找数据库的各种文件所在位置以及指定某些初始化参数,这些参数通常定义了某种内存结构有多大等.在默认情况下,MySQL实例会按照一定 ...
- Android注解使用之注解编译android-apt如何切换到annotationProcessor
前言: 自从EventBus 3.x发布之后其通过注解预编译的方式解决了之前通过反射机制所引起的性能效率问题,其中注解预编译所采用的的就是android-apt的方式,不过最近Apt工具的作者宣布了不 ...
- Android学习探索之Java 8 在Android 开发中的应用
前言: Java 8推出已经将近2年多了,引入很多革命性变化,加入了函数式编程的特征,使基于行为的编程成为可能,同时减化了各种设计模式的实现方式,是Java有史以来最重要的更新.但是Android上, ...
- 算法与数据结构(十六) 快速排序(Swift 3.0版)
上篇博客我们主要聊了比较高效的归并排序算法,本篇博客我们就来介绍另一种高效的排序算法:快速排序.快速排序的思想与归并排序类似,都是采用分而治之的方式进行排序的.快速排序的思想主要是取出无序序列中第一个 ...
- Python碎碎念
1. 如何添加路径 主要有以下两种方式: 1> 临时的 import sys sys.path.append('C:\Users\Victor\Desktop') 2> 永久的 在Linu ...