开发者

Inject attribute doesn't work for field

开发者 https://www.devze.com 2023-02-21 15:39 出处:网络
Inject attribute is not working for field. [Inject] public MyContext context; //Not injected [Inject] public MyContext context {get; set;} //Injected

Inject attribute is not working for field.

[Inject]
public MyContext context; //Not injected

[Inject]
public MyContext context {get; set;} //Injected

I am using default Ninject settings. Why fiel开发者_JAVA技巧d is not injected ?


Because it is not allowed.

From the Ninject 2 Beta announcement:

Things that were in Ninject 1.x that are not in Ninject 2:

  • Field injection: Ninject 2’s injection is now driven by expression trees, and in .NET 3.5 there is no way to set field values with an expression tree. Since this is a bad practice anyway, I decided to cut it.
0

精彩评论

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