1
依賴注入停止對所有屬性(除了明確指定的屬性)起作用。顯式屬性注入打破Unity中的其他屬性
控制器:
public class MyController : Controller
{
[Dependency]
public int RefreshInterval { get; set; }
[Dependency]
public IReportService ReportService { get; set;}
Web.config文件:
<register type="My.Web.Controllers.MyController, My.Web, Version=1.0.0.0, Culture=neutral">
<property name="RefreshInterval" value="5000"></property> <!-- This one breaks other properties, injected by default -->
</register>
<register type="My.Model.IReportService, My.Model, Version=1.0.0.0, Culture=neutral"
mapTo="My.Model.ReportService, My.Model, Version=1.0.0.0, Culture=neutral">
</register>
現在,我已經指定的屬性明確,我一定要明確指定過的所有屬性?有沒有辦法讓其他屬性仍然默認注入?