-1

I created a service class 'TeacherService' with an interface that I want to pass it into my controller's constructor, but when I try there is an error in one of the constructors

As soon as I type a comma into the constructors parameters it red unerlines

new TeacherRepository()

saying it can't resolve the constructor. Here is the code.

public class TeacherController : Controller
{
    private readonly ITeacherRepository teacherRepository;
    private  readonly ITeacherService teacherService;

    // If you are using Dependency Injection, you can delete the following constructor
    public TeacherController() : this(new TeacherRepository())
    {
    }

    public TeacherController(ITeacherRepository teacherRepository, ITeacherService teacherService)
    {
        this.teacherRepository = teacherRepository;
        this.teacherService = teacherService;
    }
chuckd
  • 13,460
  • 29
  • 152
  • 331

1 Answers1

1
public TeacherController() : this(new TeacherRepository())

You are calling the second constructor that expects two parameters with just one. Add the default TeacherService for it to compile.

Euphoric
  • 12,645
  • 1
  • 30
  • 44