I'm trying to create a parameterized constructor, as shown below:
public class TestController : Controller
{
private readonly IAppService _servico;
public DashboardController(IAppService servico)
{
_servico = servico;
}
public ActionResult Index()
{
var a = _servico.Pesquisar();
return View();
}
}
Dependency injection has been made, but it still returns the error:
No parameterless constructor defined for this object
public static class SimpleInjectorWebApiInitializer
{
public static void Initialize()
{
var container = new Container();
container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();
InitializeContainer(container);
container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
container.Verify();
SimpleInjectorMvcExtensions.GetControllerTypesToRegister(container, Assembly.GetExecutingAssembly());
}
private static void InitializeContainer(Container container)
{
Bootstrapper.Start(container);
}
}
I have tried several alternatives, but without success. Would you please let me know how I can resolve this problem?
Thank you in advance!