不确定我在这里缺少什么。我有Web API控制器但是当我使用
调用api时 http://localhost:10843/api/Lookup/GetData
我收到错误
[HttpException]: The controller for path '/api/Lookup/GetData' was not found or does not implement IController.
这是实施。请注意,我使用Unity进行依赖注入,所以我假设在运行时Unity将提供IMyService和IMapper。
public class LookupController : ApiController
{
IMyService _service = null;
IMapper _mapper = null;
public LookupController(IMyService service, IMapper mapper)
{
_service = service;
_mapper = mapper;
}
public IEnumerable<MyModel> GetData()
{
var result _service.GetData();
return _mapper.Map<IEnumerable<MyDodel>>(result);
}
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/id",
defaults: new { id = RouteParameter.Optional }
);
}
}
另外我想知道我需要默认构造函数吗?