我有一些api控制器,我想在運行時在我的mvc應用程序中註冊。 控制器本身駐留到類庫項目,看起來像:在運行時註冊自定義控制器
public class CustomController : ApiController
{
public string Get()
{
return "Hello";
}
}
我已經編譯庫(給它取名爲Injection.dll
),並在我的MVC應用程序嘗試註冊通過Unity.Mvc庫容器那些控制器
public static class UnityConfig
{
public static void RegisterComponents()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
Assembly customLogicAssembly = Assembly.LoadFrom(HttpContext.Current.Server.MapPath("~/bin/" + "Injection.dll"));
Type existingType = customLogicAssembly.GetTypes().First();
container.RegisterType(existingType);
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
}
}
如此看來,登記工作正常,我沒有錯誤,同時debuggig,但 我沒有期望的結果,當我瀏覽到API /自定義/獲取本人曾經The resource cannot be found.
錯誤瀏覽器。 請幫助我想念這裏。
你有沒有配置1路線爲web api? 2.統一控制器工廠爲您的附加自定義API控制器? –