ActionAttribute DI

时间:2016-12-16 12:15:30

标签: c# asp.net-core

我无法弄清楚如何完成以下任务:
我有一个属性:

public class Authorize : ActionFilterAttribute
  {
      private readonly IAccessPermissionRepository _repository;

      public Authorize(IAccessPermissionRepository repository)
      {
          _repository = repository;
      }
      ...
   }

IAccessPermissionRepository默认解析为IoC
我在像这样的控制器类中使用它

 [ServiceFilter(typeof(Authorize))]
        public IActionResult Index()

但现在我想将其他参数传递给构造函数,每个操作和控制器都有所不同。通常情况下我只会使用构造函数,但是......你看。

1 个答案:

答案 0 :(得分:2)

您使用TypeFilter而不是ServiceFilter,如下所示:

observe

HasDummyPrivilegeAttribute看起来像:

[TypeFilter(typeof(HasDummyPrivilegeAttribute), Arguments = new object[] { "dummyId" })]
相关问题