I've got the same problem as in this question
The error message is: A single instance of controller 'Search.Web.Controllers.AdvancedController' cannot be used to handle multiple requests. If a custom controller factory is in use, make sure that it creates a new instance of the controller for each request.
Code in Global.asax:
protected void Application_Start()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterType<AdvancedController>().InstancePerHttpRequest();
containerBuilder.RegisterType<MemoryBodyTypeRepository>().As<IBodyTypeRepository>;
containerBuilder.RegisterType<BodyTypePictureClassFinder>().As<IBodyTypePictureClassFinder>();
var container = containerBuilder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
This is some Code from AdvancedController:
private readonly IBodyTypeRepository _bodyTypeRepository;
private readonly IBodyTypePictureClassFinder _bodyTypePictureClassFinder;
public AdvancedController(IBodyTypeRepository bodyTypeRepository, IBodyTypePictureClassFinder bodyTypePictureClassFinder)
{
_bodyTypeRepository = bodyTypeRepository;
_bodyTypePictureClassFinder = bodyTypePictureClassFinder;
}
[HttpGet]
public ActionResult Index()
{
var advancedSearchViewModel = new AdvancedSearchViewModel();
return View(advancedSearchViewModel);
}
public ActionResult BodyTypes()
{
// this uses the repositories to create the ViewModel
return View(bodyTypesViewModel);
}
And the Index View:
<div>
@Html.Action("BodyTypes","Advanced")
</div>
If I execute this View I get the Message stated above. I also tried to remove the InstancePerHttpRequest or use RegisterControllers instead of regestering them explicitly, but that didn't work, too. If I use RegisterControllers I get the same Error. If I remove InstancePerHttpRequest it somehow executes the whole View two times, which is also not what I'd like to do ;)
I hope anybody can help. This is a real Showstopper for me.
Thansk a lot!!!!
Regards, Florian Fanderl