【问题标题】:Dependency Injection within outputcache filter in ASP.NET MVCASP.NET MVC 中的输出缓存过滤器中的依赖注入
【发布时间】:2014-07-24 03:41:25
【问题描述】:

有没有办法在 outputcache 属性中进行依赖注入,我可以在返回缓存之前检查数据库中的一些内容?

[CustomOutputCache(CacheProfile = "Documents")]
        public virtual ActionResult Scoresheets(int? eventId, int? gameId)
        {

【问题讨论】:

  • 最好保持属性被动,如herehere 所述。

标签: asp.net asp.net-mvc dependency-injection ninject outputcache


【解决方案1】:

这可能是另一种方法...

我没有在自定义 OutputCache 属性中尝试过 DI。但是,如果您已经尝试过并且无法连接到 DI 容器,我会模仿 OutputCache attribute behavior in an Action Filter 并在操作过滤器中使用 DI。你可能知道它是very easy to inject dependencies to the action filter 使用 DI 容器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多