Dependency Injection and .NET Attributes

微笑、不失礼 提交于 2019-12-08 18:33:24

Could you not make the logger an interface and pass it to either a property in the Attribute or through the constructor:

LoggerAttribute
{
    [Dependency]
    public ILogger Logger {get; set;}

    ...
}

If it were me though I would go for putting the logger in a base class and set up a property on it.

See this article - How to use Ninject to inject dependencies into ASP.NET MVC ActionFilters

http://codeclimber.net.nz/archive/2009/02/10/how-to-use-ninject-to-inject-dependencies-into-asp.net-mvc.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!