Using structureMap sample package in web application

25 views
Skip to first unread message

Abolfazl Davoodi Shandiz

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

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:
[HttpPost]
[ActionName("AddActivity")]
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);
      }
      else
      {
         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?

thanks

Reply all
Reply to author
Forward
0 new messages