A single instance of controller 'MySurfaceController' cannot be used to handle multiple requests.
I'm trying to use surface controllers to display a list of products. This is working fine however if I try to call this twice I get the exception:
@Html.Action("List", "Product", new { size = 10 })
@Html.Action("List", "Product", new { size = 10 })
A single instance of controller 'ProductController' cannot be used to handle multiple requests.
The way I'm using it is to call the Product list controller via a Macro so that the user can add a product list anywhere.
Controller:
/// <summary>
/// Product details controller
/// </summary>
public class ProductController : SurfaceController
{
private readonly string uri = ConfigurationManager.AppSettings["uri:searchApi"];
public ActionResult List(ProductSearch request, int size = 10)
{
string requestUri = "workgroups/?page=0&pageSize=" + size;
ProductSearch search = SearchHelper.CreateSearch(request, null);
using (var client = new HttpClient())
{
client.BaseAddress = new Uri(uri);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// New code:
HttpResponseMessage response = client.PostAsJsonAsync(requestUri, search).Result;
if (response.IsSuccessStatusCode)
{
WorkGroupSearchResult searchResult = response.Content.ReadAsAsync<WorkGroupSearchResult>().Result;
return PartialView("List", new SearchModel(this.CurrentPage, searchResult));
}
else
{
throw new HttpRequestException("Request failed: " + response.StatusCode.ToString());
}
}
}
}
A single instance of controller 'MySurfaceController' cannot be used to handle multiple requests.
I'm trying to use surface controllers to display a list of products. This is working fine however if I try to call this twice I get the exception:
The way I'm using it is to call the Product list controller via a Macro so that the user can add a product list anywhere.
Controller:
Any help would be much appreciated.
This was caused because I'm using th custom IoC framework StructureMap.
Once I added the following to the container it runs fine:
is working on a reply...