全局异常处理程序通过创建HttpResponseMessage来处理从控制器抛出的异常。这显然会导致真正的http错误。
与Autofac集成后,异常不会被视为失败。客户认为这是一个成功的回应。
是否与autofac配置有关?
Microsoft.AspNet.WebApi - {5.2.0}
Autofac - {3.5.2}
Autofac.WebApi2 - {4.0.0}
Autofac配置:
var builder = new ContainerBuilder();
var modules = new List<Module>() { new AutofacModule() };
modules.ForEach(m => builder.RegisterModule(m));
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(builder.Build());
AutofacModule:
protected override void Load(ContainerBuilder builder)
{
var config = GlobalConfiguration.Configuration;
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);
}