如何给过滤器ActionFilterAttribute也用上构造函数注入呢?

一般自定义的过滤器直接用特性方式标识就能使用

[ContentFilter]

因为构造函数在使用的时候要求传参,然后我们可以使用这个

ServiceFilter

在ASP.NET Core里,我们可以使用ServiceFilter来完成这个需求。

ServiceFilter允许我们解析一个已经添加IoC容器的服务,因此我们需要把ContentFilter注册一下。

services.AddScoped<ContentFilter>();

在需要的地方直接用特性方式标识

[ServiceFilter(typeof(ContentFilter))]

然后发现已经能被实例化使用了

最新文章

  1. java.lang.NoClassDefFoundError:TagSupport
  2. LintCode Search Insert Position
  3. Python基础学习笔记(五)常用字符串内建函数
  4. 系统监控、诊断工具之top
  5. 让Delphi XE2程序支持UAC
  6. Cordova环境搭建与hello word
  7. libpng warning: iCCP: known incorrect sRGB profile
  8. Debian 8下手工安装 Eclipse CDT neon.2
  9. nginx 转将http跳转到https
  10. Redis使用sortedset缓存IP段数据
  11. ORM正向和反向查询
  12. oracle.exe 内存占用过大
  13. C++ 设置透明背景图片
  14. 如何理解nexus
  15. 支持辉光效果的Label
  16. Thinkphp5笔记六:公共模块common的使用
  17. Codeforces Round #449 (Div. 1)C - Willem, Chtholly and Seniorious
  18. 程序中使用7z.exe解压不完整的问题
  19. IIS 配置网站
  20. AVMoviePlayer 视频播放器

热门文章

  1. Artifact tlks: com.intellij.javaee.oss.admin.jmx.JmxAdminException: com.intellij.execution.ExecutionException: E:\IDEAspace\tlksArtfacts\tlks.war not found for the web module.
  2. 第09组 Beta冲刺(2/4)
  3. 【转】Fiddler抓包和修改WebSocket数据,支持wss
  4. centos安装redis 5.0版本的集群
  5. ai segmentation
  6. meta name=&quot;location&quot; 标签的使用
  7. RSA 签名、验证、加密、解密帮助类
  8. [LeetCode] 666. Path Sum IV 二叉树的路径和 IV
  9. python jieba 词云
  10. SQL查询优化思维即SQL子查询