-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
AOP
ansonzhang edited this page Jun 11, 2019
·
4 revisions
https://www.cnblogs.com/laozhang-is-phi/category/1290896.html
A、内存缓存AOP
B、Redis缓存AOP
C、日志AOP
这三个AOP对应的文件地址:
├─Blog.Core
├──AOP
│ ├─BlogCacheAOP.cs
│ ├─BlogLogAOP.cs
│ ├─BlogRedisCacheAOP.cs
D、SqlSugar 生产Sql语句AOP(在仓储层 DbContext.cs 上下文中 _db.Aop.OnLogExecuting)
在 appsettings.json 文件中配置:
"RedisCaching": {
"Enabled": false,
"ConnectionString": "127.0.0.1:6319"
},
"MemoryCachingAOP": {
"Enabled": true
},
"LogAOP": {
"Enabled": true
},
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());//允许将拦截器服务的列表分配给注册。
有疑问,请自行查看博客园文章:https://www.cnblogs.com/laozhang-is-phi/p/9495618.html#autoid-1-0-0
或者加 QQ 群:867095512
-
- AOP
- Appsettings
- Async-Await
- Authorization-Ids4
- Authorization-JWT
- AutoMapper
- CORS
- DI-AutoFac
- DI-NetCore
- Filter
- GlobalExceptionsFilter
- HttpContext
- Log4
- MemoryCache
- Middleware
- MiniProfiler
- publish
- Redis
- Repository
- SeedData
- SignalR
- SqlSugar
- SqlSugar-Codefirst&DataSeed
- SqlSugar-SqlAOP
- Swagger
- T4
- Test-xUnit
- Temple-Nuget
- FAQ page is a good place to see whether your question is already asked.
- Ask a question in cnblogs if you need help.
- Submit an issue if you found a bug or have a feature request.
- Open a pull request when you prepared to contribute. Before that, it is encouraged to open an issue to discuss.