Вопрос

Following on from my earlier question on Ninject

I still cannot get property injection working..

The constructor parameter is injected but the property is not.. Am I doing this wrong??

    public class CokeConsumer
    {
    [Inject]
    public IDrinkCan Drink { get; set; }

    public CokeConsumer(IDrinkCan drink)
    {
        Drink = drink;
        Drink.OpenCan(330);
    }

    public void DrinkSomeCoke(int amount)
    {
        Drink.DrinkSome(amount);
    }
}
Это было полезно?

Решение

You cant do that silly.. you cant expect properties to be set before the object has been constructed!!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top