gpt4 book ai didi

asp.net-web-api - 为什么在 OWIN 中使用带有 WebApi 自托管的简单注入(inject)器时会出现此 ActivationException?

转载 作者:行者123 更新时间:2023-12-02 03:15:38 30 4
gpt4 key购买 nike

我有一个非常简单的 Web Api v2.2 自托管在 OWIN

public class StartUp
{
public void Configuration(IAppBuilder appBuilder, IConfigReader configReader)
{
var container = new Container();

container.Register<IConfigReader, ConfigReader>();

var config = new HttpConfiguration();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.DependencyResolver = new SimpleInjectorWebApiDependencyResolver(container);
appBuilder.UseWebApi(config);
}
}

当我在我的 Main() 上使用时:

WebApp.Start(baseAddress, appBuilder => 
new StartUp().Configuration(appBuilder, new ConfigReader()));

但是,当我尝试执行最后一行 appBuilder.UseWebApi(config); 时,出现以下异常:

A first chance exception of type 'SimpleInjector.ActivationException' occurred in SimpleInjector.dll

Additional information: The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type.

完整堆栈:

SimpleInjector.ActivationException occurred _HResult=-2146233088
_message=The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type.
HResult=-2146233088 IsTransient=false Message=The given type IHostBufferPolicySelector is not a concrete type. Please use one of the other overloads to register this type. Source=SimpleInjector
StackTrace: at SimpleInjector.Advanced.DefaultConstructorResolutionBehavior.VerifyTypeIsConcrete(Type implementationType) InnerException:

问题不在于单个接口(interface),它看起来像 SimpleInjector 试图为每个单个接口(interface)找到一个绑定(bind);如果我为 IHostBufferPolicySelector 提供一个虚拟实现,它会抛出一些其他接口(interface),例如IExceptionHandler

有一个相关线程 HERE但我不确定它与 SimpleInjector 有何关系?自主机是一个控制台应用程序,安装了以下软件包:

  • 简单注入(inject)器 ASP.NET Web API 集成 v2.61
  • 简单注入(inject)器执行上下文范围 v2.61
  • 简单注入(inject)器 v2.61
  • OWIN v1.0
  • Microsoft.Owin v2.0.2
  • Microsoft.Owin.Hosting v2.0.2
  • 微软 ASP.NET Web API 2.2 OWIN v5.2.2
  • Microsoft ASP.NET Web API 2.2 OWIN 自托管 v5.2.2

最佳答案

根据简单注入(inject)器:

The exceptions you are showing are 'first chance exceptions'. These exceptions are thrown by Simple Injector but they are caught and processed by Simple Injector and they won't bubble up the call stack. It is possible that you see them in some debugger output window, but they are quite normal and nothing to worry about.

关于asp.net-web-api - 为什么在 OWIN 中使用带有 WebApi 自托管的简单注入(inject)器时会出现此 ActivationException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26652851/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com