I am trying to call in to a repository method to fetch some data, which be returned from a Web Api 'Get' request.
public class BookRepository : IBookRepository
{
public Book GetBookInfo()
{
return new Book
{
Title = "Book1",
Chapters = new List<string>
{
"Chapter1",
"Chapter2",
"Chapter3",
"Chapter4"
}
};
My apicontroller:
public class BooksController : ApiController
{
private readonly IBookRepository _repository;
public BooksController () { }
public BooksController (IBookRepository repository)
{
this._repository = repository;
}
// GET api/books
public Book Get()
{
return _repository.GetBookInfo();
}
The issue is that when I navigate to this in the browser e.g. 'http://localhost:49852/api/books' I am getting a NullReferenceException. Please can you explain why and how to rectify?
repositoryonBooksControllerconstructor?