不知怎的,我找不到有同样问题的人。
我们有一个基于插件的项目,在主文件夹中我们有Plugin Starter,Bootstrapper和一些依赖项。
插件位于“插件”文件夹中,在其他文件夹中。
我的Startup.cs文件如下:
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
appBuilder.Use(async (env, next) =>
{
new object().Info(string.Concat("Http method: ", env.Request.Method, ", path: ", env.Request.Path));
await next();
new object().Info(string.Concat("Response code: ", env.Response.StatusCode));
});
RunWebApiConfiguration(appBuilder);
}
private static void RunWebApiConfiguration(IAppBuilder appBuilder)
{
var httpConfiguration = new HttpConfiguration();
httpConfiguration.Routes.MapHttpRoute(
name: "WebApi"
, routeTemplate: "{controller}/{id}"
, defaults: new { id = RouteParameter.Optional }
);
appBuilder.UseWebApi(httpConfiguration);
}
}
调用如下:
WebApp.Start<Startup>("http://localhost/MyRestApi");
如果我在相同的文件夹上加载程序集,没问题,但是如果我将它加载到“所属”的地方,我就无法让Owin找到它。
任何人都遇到过这个或有任何想法?我可能会想到App.config中的配置行,但我不认为这是一个解决方案。
更新1:
当我在主目录上复制Rest Service程序集但是它被加载两次时,我再次使系统工作,这是一个很大的问题。
当我发送Rest请求时,我收到以下消息:
{"Message":"An error has occurred.","ExceptionMessage":"Multiple types were found that match the controller named 'ExternalOrder'. This can happen if the route that services this request ('{controller}/{id}') found multiple controllers defined with the same name but differing namespaces, which is not supported.\r\n\r\nThe request for 'ExternalOrder' has found the following matching controllers:\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController\r\nInternalOrderValidationPlugin.Controllers.ExternalOrderController","ExceptionType":"System.InvalidOperationException","StackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
答案 0 :(得分:0)
好的,在互联网上闲逛之后,我找到了一个解决方案,即依赖注入。
此帖子中有#34; How to use DI container when OwinStartup&#34;你可以找到很多可能性,但是我实现并解决了我的问题的是这篇博文:
https://damienbod.wordpress.com/2013/10/01/self-host-webapi-with-owin-and-unity/
我希望这可以帮助其他人。