mirror of
https://github.com/anjoy8/Blog.Core.git
synced 2025-02-08 02:39:26 +08:00
Updated AOP (markdown)
parent
9b329cf754
commit
6581c5224f
53
AOP.md
53
AOP.md
|
@ -2,10 +2,14 @@
|
|||
[https://www.cnblogs.com/laozhang-is-phi/category/1290896.html](https://www.cnblogs.com/laozhang-is-phi/category/1290896.html)
|
||||
|
||||
### 2、哪些AOP
|
||||
|
||||
A、内存缓存AOP
|
||||
|
||||
B、Redis缓存AOP
|
||||
|
||||
C、日志AOP
|
||||
D、SqlSugar 生产Sql语句AOP(在仓储层 DbContext.cs 上下文中 _db.Aop.OnLogExecuting)
|
||||
|
||||
这三个AOP对应的文件地址:
|
||||
|
||||
```
|
||||
├─Blog.Core
|
||||
|
@ -17,7 +21,11 @@ D、SqlSugar 生产Sql语句AOP(在仓储层 DbContext.cs 上下文中 _db.Aop
|
|||
|
||||
```
|
||||
|
||||
### 3、配置AOP
|
||||
|
||||
D、SqlSugar 生产Sql语句AOP(在仓储层 DbContext.cs 上下文中 _db.Aop.OnLogExecuting)
|
||||
|
||||
|
||||
### 3、配置AOP是否启用
|
||||
|
||||
在 appsettings.json 文件中配置:
|
||||
|
||||
|
@ -33,3 +41,44 @@ D、SqlSugar 生产Sql语句AOP(在仓储层 DbContext.cs 上下文中 _db.Aop
|
|||
},
|
||||
|
||||
|
||||
|
||||
### 4、Startup.cs 中注入服务
|
||||
```
|
||||
builder.RegisterType<BlogCacheAOP>();//可以直接替换其他拦截器
|
||||
builder.RegisterType<BlogRedisCacheAOP>();//可以直接替换其他拦截器
|
||||
builder.RegisterType<BlogLogAOP>();//这样可以注入第二个
|
||||
|
||||
```
|
||||
---------------------
|
||||
|
||||
```
|
||||
// AOP 开关,如果想要打开指定的功能,只需要在 appsettigns.json 对应对应 true 就行。
|
||||
var cacheType = new List<Type>();
|
||||
if (Appsettings.app(new string[] { "AppSettings", "RedisCaching", "Enabled" }).ObjToBool())
|
||||
{
|
||||
cacheType.Add(typeof(BlogRedisCacheAOP));
|
||||
}
|
||||
if (Appsettings.app(new string[] { "AppSettings", "MemoryCachingAOP", "Enabled" }).ObjToBool())
|
||||
{
|
||||
cacheType.Add(typeof(BlogCacheAOP));
|
||||
}
|
||||
if (Appsettings.app(new string[] { "AppSettings", "LogAOP", "Enabled" }).ObjToBool())
|
||||
{
|
||||
cacheType.Add(typeof(BlogLogAOP));
|
||||
}
|
||||
|
||||
builder.RegisterAssemblyTypes(assemblysServices)
|
||||
.AsImplementedInterfaces()
|
||||
.InstancePerLifetimeScope()
|
||||
.EnableInterfaceInterceptors()//引用Autofac.Extras.DynamicProxy;
|
||||
// 如果你想注入两个,就这么写 InterceptedBy(typeof(BlogCacheAOP), typeof(BlogLogAOP));
|
||||
// 如果想使用Redis缓存,请必须开启 redis 服务,端口号我的是6319,如果不一样还是无效,否则请使用memory缓存 BlogCacheAOP
|
||||
.InterceptedBy(cacheType.ToArray());//允许将拦截器服务的列表分配给注册。
|
||||
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user