Using structureMap sample package in web application

Skip to first unread message

Abolfazl Davoodi Shandiz

Jun 19, 2018, 12:41:22 PM6/19/18
to structuremap-users

I use both of MVC and WebApi in my application. For implementing IoC i use structure map sample package(StructureMap.WebApi2)

In MVC controllers everything is ok but when i use web api, for example post something to server i get this error:

[HttpException]: The controller for path '/api/Activity/AddActivity' was not found or does not implement IController.
   at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
   at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
This is AddActivity action:
public HttpResponseMessage AddActivity(ActivityDTO activityDTO)
      ActivityDTO data = activityDTO;
      HttpResponseMessage response = new HttpResponseMessage();

      data.UserID = User.Identity.GetUserId();

      int id = _activityServices.Add(data);

      if (id != -1)
         response = this.Request.CreateResponse(HttpStatusCode.OK, id);
         response=this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Activity doesn't save.");

       return response;

I check the path of action and it's correct.

can you help me?


Reply all
Reply to author
0 new messages