Home > Net >  Getting dependency service object null in helper class
Getting dependency service object null in helper class

Time:10-20

I have created one helper class and injected one service in this way, but when I try to call function from that service object then getting error like service was null.

 public class LogHelper
    {
        public CommonServiceType _service;

        public LogHelper(CommonServiceType service)
        {
            _service = service;
        }

        public async void AddLog()
        {

            httpResponseMessage = await _service.SendData();
        }
}

But here _service I am getting null and getting error on _service was null

CodePudding user response:

I have same kind of issue happen earlier..

My problem was I was not passing object when I try to call function. So I did in below way and it worked for me.

LogHelper log = new LogHelper(_yourserviceobject);
log.callfunction()
  • Related