开发者

Inject into attribute?

I have a [Logger] attribute for my asp.net-mvc projects. This LoggerAttribute takes a ILoggerService in it's constructor.

For regular objects (e.g. my controlle开发者_JS百科rs) it works, but attributes don't seem to be resolved.

How can I have Turbine inject the ILoggerService?


Attribute arguments must be constant expressions, so you cannot instantiate an object to be given to an attribute.

http://msdn.microsoft.com/en-us/library/5y0xyec6.aspx

What I would do is require your controller to accept a ILoggerServer in it's constructor and have Turbine inject into your controller's constructor.


Is your Logger attribute an Action|Result|Error|Authorization filter? If so, you can use the InjectableFilterAttribute class to specify the type of the filter you want Turbine to inject for you. This way you can support ctor injection to your services.

To see how this is done, check out the Filter Injection sample that ships with Turbine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜