Update
Tried to clarify my problem
I have a ASP.NET 5 Web Api application. I'm trying to create a controller class that makes use of a custom base controller. As soon as I add a constructor to the base controller then MVC can no longer find the Get() end point defined in the Generic class.
This works:
When I navigate to /api/person then the Get() end point is triggered defined in the Generic class
Generic:
public class Generic
{
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
PersonController
[Route("api/[controller]")]
public class PersonController : Generic
{
}
This doesn't work
When I navigate to /api/person then the Get() end point is not triggered. The only thing that is added is a constructor in both the Generic class and the PersonController class.
public class Generic
{
protected DbContext Context { get; set; }
public Generic(DbContext context)
{
Context = context;
}
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
}
PersonController
[Route("api/[controller]")]
public class PersonController : Generic
{
public PersonController(DbContext context) : base(context) { }
}
Is this a bug or am I doing something wrong?
CustomBasemust inherit fromController... And if you have that, you should read How to Ask and create a minimal reproducible example. Show the exact error you get and the research you did to resolve that error. If you add a parameterless constructor, then the default controller factory indeed cannot instantiate your controllers anymore, and you can solve that using dependency injection or by introducing your own controller factory. All of this has been covered before, so try searching.Controllerclass. But even when I do add it, I still cannot call myGet()endpoint. Agian, it does work when I remove theconstructorsfromPersonControllerand myGenericclass