【发布时间】:2017-03-17 17:20:28
【问题描述】:
我在 VS2013 下有一个 OData V3 C# 项目,我想在运行时在单独的类库中加载/注入 ODataController 并让该服务成为路由。问题是我无法获得解决控制器的路线。例如http://localhost/odata/Tests
"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 Register() 方法中,我有这个:
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() );
}
谁能明白为什么我无法获得解析到控制器类的路由?我是否错过了将它们联系在一起的东西?
【问题讨论】:
标签: c# asp.net-web-api2 odata