1
我在VS2013下有一個OData V3 C#項目,我想在運行時在單獨的類庫中加載/注入ODataController,並讓該服務成爲路由。問題是我無法獲得解決控制器的路線。例如http://localhost/odata/Tests在運行時添加OData V3控制器 - 找不到控制器
"No type was found that matches the controller named 'TestsController'"
這裏是我的控制器看起來像在單獨的類庫:
namespace WebApi.Extensions
{
public class TestsController : ODataController
{
var t = "some string";
public IHttpActionResult Get(ODataQueryOptions<Test> queryOptions)
{
...
}
}
}
而且在我的WebAPI註冊()方法,我有這樣的:
public static void Register(HttpConfiguration config)
{
var builder = new ODataConventionModelBuilder();
<lots of 'local' builder.EntitySet<***>("***") calls>
builder.EntitySet<Test>("Tests");
var assembly = Assembly.LoadFrom("<full path to classlib.dll>");
// test that we can find and load an instance
var type = assembly.GetType("WebApi.Extensions.TestsController");
var obj = Activator.CreateInstance(type);
// no errors so far. I can 'see' into 'obj'
config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
}
有人能看到爲什麼我無法獲得解決控制器類的路線?我是否錯過了將它連接在一起的東西?