注入属性不野外作业 [英] Inject attribute doesn't work for field

查看:159
本文介绍了注入属性不野外作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注入属性不工作的领域。

Inject attribute is not working for field.

[Inject]
public MyContext context; //Not injected

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

我使用的默认Ninject设置。为什么字段不注入?

I am using default Ninject settings. Why field is not injected ?

推荐答案

由于这是不允许的。

从Ninject 2 Beta版公告

From the Ninject 2 Beta announcement:

的事情,是在Ninject 1.x中的   不在Ninject 2:

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

      
  • 字段注入:Ninject 2的   注射现在由前pression驱动   树木,并在.NET 3.5也没办法   用一个前pression设置字段值   树。由于这是一个不好的做法   反正,我决定削减它。
  •   
  • 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.

这篇关于注入属性不野外作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆