I am trying to understand the concept of Injection Dependency. Below is an example that I am trying to debug. Here I created the Customer class, whose dependencies I have Injected in its constructor. Now that I have called this.Iorder.GetOrderDetails(); in the Index method, he gave me a NullReferenceException error and asked me to use the new keyword to create an object to call the method. When I moved this call to this.Iorder.GetOrderDetails(); to another method GetCutomerDetails() and called this method in the index method, it works.
Question I canβt understand why the call to the this.Iorder.GetOrderDetails() method does not work in the Index method and why it works in GetCutomerDetails()
public interface IorderDetails { void GetOrderDetails(); } public class CustomerModel : IorderDetails { public void GetOrderDetails() {} }
Controller:
public class CustomerController: Controller { private IorderDetails Iorder;
source share