views:

27

answers:

1

Dependency injection stops working for all properties, except the one specified explicitly.

Controller:

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>

Now that i have specified a property explicitly, do i have to specify all the properties explicitly too? Is there a way to have other properties still be injected by default?

A: 

API or config file overrides the attributes. That's just the way it works. Otherwise there'd be no way to turn attribute based injection OFF.

Chris Tavares