存储库注入授权过滤器 C# .NET API

我需要将存储库注入到操作过滤器中,在本例中为自定义身份验证过滤器。 使用实体框架、StructureMap 数据注入、存储库模式、.NET API。

通过这种设置,类可以注入像下面的 _customerRepo 这样的存储库:

public class PaymentController : ApiController
{
    private GenericRepository<Customer> _customerRepo;

    public PaymentController(GenericRepository<Customer> customerRepo)
    {    
       _customerRepo = customerRepo;
    }

但是,由于我的自定义 Authorize 过滤器没有实例化,所以我不确定构造函数在这里是如何工作的。

public class Authorizeuser : AuthorizeAttribute
   {
       public Task AuthenticateAsync(HttpAuthenticationContext context,CancellationToken cancellationToken)
       {
          //I want a repository here!
          return null;
       }
iCMS 回答:存储库注入授权过滤器 C# .NET API

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/463740.html

大家都在问