Asp.net web api 带Owin的自动传真机
我对Autofac有问题。文档中明确指出,在使用Web API 2和OWIN时,您不得在任何地方使用Asp.net web api 带Owin的自动传真机,asp.net-web-api,asp.net-web-api2,owin,autofac,Asp.net Web Api,Asp.net Web Api2,Owin,Autofac,我对Autofac有问题。文档中明确指出,在使用Web API 2和OWIN时,您不得在任何地方使用全局配置 OWIN集成中的一个常见错误是使用GlobalConfiguration.Configuration。在OWIN中,您从头开始创建配置。使用OWIN集成时,不应在任何地方引用GlobalConfiguration.Configuration 可在此处(页面底部)找到: 但无论我做什么,我都无法使用Autofac工作: config.DependencyResolver = new Aut
全局配置
OWIN集成中的一个常见错误是使用GlobalConfiguration.Configuration。在OWIN中,您从头开始创建配置。使用OWIN集成时,不应在任何地方引用GlobalConfiguration.Configuration
可在此处(页面底部)找到:
但无论我做什么,我都无法使用Autofac工作:
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
而不是:
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
当我使用后者时,它是有效的。
有人知道为什么吗?好的,我知道了。如果其他人有这个问题,我会把答案贴在这里。
如文档所述,您不能在任何地方使用GlobalConfiguration
。。。。
所以我搜索了一下,在别的地方找到了。
我有这个:
GlobalConfiguration.Configure(WebApiConfig.Register);
应该是:
WebApiConfig.Register(config);
当我把它修好后,我就可以使用正确的