我需要将存储库注入到操作过滤器中,在本例中为自定义身份验证过滤器。 使用实体框架、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;
}