ASP.NET Core 过滤器中使用依赖注入
2024-10-10 11:21:12
如何给过滤器ActionFilterAttribute也用上构造函数注入呢?
一般自定义的过滤器直接用特性方式标识就能使用
[ContentFilter]
因为构造函数在使用的时候要求传参,然后我们可以使用这个
ServiceFilter
在ASP.NET Core里,我们可以使用ServiceFilter来完成这个需求。
ServiceFilter允许我们解析一个已经添加IoC容器的服务,因此我们需要把ContentFilter注册一下。
services.AddScoped<ContentFilter>();
在需要的地方直接用特性方式标识
[ServiceFilter(typeof(ContentFilter))]
然后发现已经能被实例化使用了
最新文章
- java.lang.NoClassDefFoundError:TagSupport
- LintCode Search Insert Position
- Python基础学习笔记(五)常用字符串内建函数
- 系统监控、诊断工具之top
- 让Delphi XE2程序支持UAC
- Cordova环境搭建与hello word
- libpng warning: iCCP: known incorrect sRGB profile
- Debian 8下手工安装 Eclipse CDT neon.2
- nginx 转将http跳转到https
- Redis使用sortedset缓存IP段数据
- ORM正向和反向查询
- oracle.exe 内存占用过大
- C++ 设置透明背景图片
- 如何理解nexus
- 支持辉光效果的Label
- Thinkphp5笔记六:公共模块common的使用
- Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious
- 程序中使用7z.exe解压不完整的问题
- IIS 配置网站
- AVMoviePlayer 视频播放器
热门文章
- Artifact tlks: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: E:\IDEAspace\tlksArtfacts\tlks.war not found for the web module.
- 第09组 Beta冲刺(2/4)
- 【转】Fiddler抓包和修改WebSocket数据,支持wss
- centos安装redis 5.0版本的集群
- ai segmentation
- meta name=";location"; 标签的使用
- RSA 签名、验证、加密、解密帮助类
- [LeetCode] 666. Path Sum IV 二叉树的路径和 IV
- python jieba 词云
- SQL查询优化思维即SQL子查询