문제

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