Somehow I can't find someone having the same problem.
We have a plugin based project, on the main folder we have the Plugin Starter, the Bootstrapper, and some dependencies.
The plugins are in the "Plugins" folder and within, are some other folders.
My Startup.cs file is as following:
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);
}
}
The call is made as following:
WebApp.Start<Startup>("http://localhost/MyRestApi");
if I load the Assembly on the same folder, no problem, but if I load it where it "belongs", I can't get Owin to find it.
Anyone had ever ran into this or have any idea? I might think of something like a configuration line in the App.config, but I don't find this as a solution.
UPDATE 1:
I get the System working again when I copy the Rest Service assembly on the main directory but then it is loaded two times, which is a big problem.
When I send a Rest request, I get the following message:
{"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()"}
Ok, after wandering around on the internet, I found a solution, and namely Dependency Injection.
Here in this post "How to use DI container when OwinStartup" you can find a lot of possibilities, but the one that I implemented and solved my problem, was this blog post:
https://damienbod.wordpress.com/2013/10/01/self-host-webapi-with-owin-and-unity/
I hope this can help anyone else.