I am inheriting ApiController and below is my overridden ExecuteAsync method with dependency injection,
public abstract class BaseController : ApiController
{
private IMyService _myService;
public PersonModel person;
protected BaseController(IMyService myService)
{
_myService = myService;
}
public override Task<HttpResponseMessage> ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)
{
_myService.Initialize(person);
}
}
This is my service interface,
public interface IMyService
{
HttpResponseMessage Initialize(PersonModel person);
}
Here is the class,
public class MyService : IMyService
{
public HttpResponseMessage Initialize(PersonModel person)
{
//Initializing person model from db
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
When I execute this method, person object in the BaseController class is still null. What should I change to initialize the object in abstract class?