Castle Windsor won't inject Logger in a property!

前端 未结 3 555
再見小時候
再見小時候 2020-12-19 07:56

I try to inject log4net in a ILogger property of my service class but the property is always NULL!

I\'ve seen this topic but it doesn\'t help me!

How can I g

3条回答
  •  攒了一身酷
    2020-12-19 08:34

    A problem is where you are checking it:

     public ILogger Logger
        {
            get { return logger; }
            set { logger = value; }
        }
    
        public LogicClass1()
        {
            logger.Debug("Here logger is NullLogger!");
        }
    

    The property injection will not happen until after the constructor is run, so checking the property value in the constructor will never show the value you are expecting

提交回复
热议问题