开发者

Is it possible to use C# DataAnnotations with IOC containers?

Is it possible to use C# DataAnnotations with IOC containers? I've got a ValidationAttribute that I'd like to inject a resolved object into the attribute class after the class is instantiated. Basicly, I want to acce开发者_如何学Goss an annotation from an instantiated class. Or maybe I'm thinking about this backwords and should use validationContext.ObjectInstance?


There's no clean way of using this (with DI). You can however use IoC if you create a static method to access the current IoC Container. It's pretty nasty but it's the only solution I found.

By static I mean static accessor that grabs it from the application or request cache.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜