2016-11-03 2 views
1

ODataController를 런타임시 별도의 클래스 라이브러리에로드/삽입하고 해당 서비스를 라우트하고 싶은 VS2013 아래에 OData V3 C# 프로젝트가 있습니다. 문제는 컨트롤러로 해석 할 경로를 얻을 수 없다는 것입니다. 예 :런타임에 OData V3 컨트롤러 추가 - 컨트롤러를 찾을 수 없습니다.

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()); 

} 

사람이 이유를 볼 수 :이이

namespace WebApi.Extensions 
{ 
    public class TestsController : ODataController 
    { 
    var t = "some string"; 

    public IHttpActionResult Get(ODataQueryOptions<Test> queryOptions) 
    { 
     ... 
    } 
    } 
} 

그리고 내 WebApi 등록() 메소드 : http://localhost/odata/Tests

"No type was found that matches the controller named 'TestsController'" 

여기 내 컨트롤러는 별도의 클래스 라이브러리에서의 모습입니다 컨트롤러 클래스로 해결할 경로를 얻을 수 없습니까? 나는 그것을 함께 묶는 것을 놓치고 있습니까?

답변

0

제가 누락 된 것을 발견했습니다.

Customizing controller discovery in ASP.Net

당신은 기본적으로 자신의를 작성하고 당신이 (IIS에서 호스팅하는 경우) 자동 bin 디렉토리에서 해제되는 어셈블리의 목록을 어디에서 사용자 정의 DefaultAssembliesResolver을 등록하고 어떤 디렉토리에서 자신의 어셈블리를 추가하려면 필요.

참고 : 위의 링크에 게시 된 소스 코드에는 버그가 있습니다. 블로그 댓글을 살펴보십시오.

관련 문제