【发布时间】:2013-06-27 21:39:15
【问题描述】:
我正在尝试将自定义 IHttpActionInvoker 添加到我的 WebAPI 应用程序,以防止在我的操作方法中需要大量重复的异常处理代码。
除了this article 之外,似乎没有太多关于如何做到这一点的信息。根据文章编写我的 IHttpActionInvoker 后,我添加了以下代码:
GlobalConfiguration.Configuration.Services.Remove(typeof(IHttpActionInvoker),
GlobalConfiguration.Configuration.Services.GetActionInvoker());
GlobalConfiguration.Configuration.Services.Add(typeof(IHttpActionInvoker),
new MyApiControllerActionInvoker());
进入我的 Global.asax 文件中的一个方法。现在,在执行对我的 API 的调用时,我在 Remove() 方法中得到以下异常:
The service type IHttpActionInvoker is not supported
我想我有两个问题。
考虑到关于编写自定义 IHttpActionInvoker 类的情况并不多见,这是否被认为是解决 WebAPI 应用程序中异常处理的好方法?
有谁知道为什么我在执行
Remove()方法时会得到这样的异常以及如何最好地解决这个特定问题?
【问题讨论】:
标签: c# asp.net-mvc asp.net-web-api