我有一个问题Autofac。该文档明确指出,当使用 Web API 2 和 OWIN 时,您must not use GlobalConfiguration.Configuration
任何地方:
OWIN 集成中的一个常见错误是使用 GlobalConfiguration.Configuration。在 OWIN 中,您从头开始创建配置。使用 OWIN 集成时,不应在任何地方引用 GlobalConfiguration.Configuration。
可以在这里找到(在页面底部):http://autofac.readthedocs.io/en/latest/integration/webapi.html http://autofac.readthedocs.io/en/latest/integration/webapi.html
但无论我做什么,我都无法得到Autofac工作使用:
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
代替:
GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
当我使用后者时,它有效。
有谁知道为什么?
好吧,我明白了。我将在这里发布答案,以防其他人遇到这个问题。
正如文档所述,您不能使用GlobalConfiguration
任何地方......
所以我进行了搜索,并在其他地方找到了它。
我有这个:
GlobalConfiguration.Configure(WebApiConfig.Register);
这应该是:
WebApiConfig.Register(config);
当我解决这个问题时,我能够使用正确的
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)