问题描述
我需要将存储库注入到操作过滤器中,在本例中为自定义身份验证过滤器。 使用实体框架、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;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)