如何做到依赖注入到行动上筛选的ASP.NET Web API [英] How to do dependency injection to Action Filter on ASP.NET Web API

查看:277
本文介绍了如何做到依赖注入到行动上筛选的ASP.NET Web API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的卡住的进场做依赖注入到网页API的行为过滤器。我有一个动作过滤器是这样的:

I really get stuck on the approach to do dependency injection into action filter of web api. I have an action filter like this:

public class AuthorizationAttribute : ActionFilterAttribute
{
    public IApiKeyRepository Repository { get; set; }

    private Guid GetApiKey(string customerKey)
    {
        return Repository.GetApiKey(customerKey);
    }

    public override void OnActionExecuting(HttpActionContext actionContext)
    {        
    }
}

我想用温莎做对物业库属性注入(但它并不重要IoC容器使用)

I would like to do property injection on the property Repository by using Windsor (but it does not matter which IoC container is used)

我没拿出来定制FilterProvider,但它并没有为我工作了,没有任何人有这个解决方案或运行code?这将是更AP preciated

I did come up to customize FilterProvider but it did not work out for me, does anyone have solution or running code on this? it will be much appreciated

推荐答案

我已经写了一篇博客文章专门用于注入依赖成实现System.Net.Http.Filters.ActionFilterAttribute的WebAPI操作过滤器。它确实使用自定义的IFilter供应商。我使用的是国际奥委会StructureMap。

I have written a blog post specifically for injecting dependencies into WebAPI Action Filters that implement the System.Net.Http.Filters.ActionFilterAttribute. It does indeed use a custom IFilter provider. The IoC I am using is StructureMap.

<一个href=\"http://evolutionarydeveloper.blogspot.co.uk/2012/11/webapi-actionfilter-dependency.html\">http://evolutionarydeveloper.blogspot.co.uk/2012/11/webapi-actionfilter-dependency.html

这篇关于如何做到依赖注入到行动上筛选的ASP.NET Web API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆