我被卡住了.我正在使用这里概述的wcf web api p6 Ninject与WCF Web API Preview 5一起使用的方法,但是测试版中的mvc实现有些不同.这里有一篇很好的文章http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver讨论构建自己的自定义依赖项解析器,但是我想使用我用于我的mvc视图控制器的相同实现...例如Ninject.我在文章中也尝试了一些基于IoC Unity示例的内容,但还没有任何内容消失.任何帮助我指向正确方向的人都会非常感激.我也会继续自己挖掘.提前致谢!
这就是我在的地方.我正在使用WebActivator来引导代码,但我已经把它放到了Application_Start()中,只是为了更多的东西.
protected void Application_Start()
{
var kernel = new StandardKernel(new MyNinjectModule());
GlobalConfiguration.Configuration.ServiceResolver.SetResolver(new NinjectDependencyResolver(kernel));
}
Run Code Online (Sandbox Code Playgroud)
和我收到以下错误:
类型Ninject.Web.Mvc.NinjectDependencyResolver似乎不执行Microsoft.Practices.ServiceLocation.IServiceLocator.
参数名称:commonServiceLocator
找到解决方案
也许有/将会有一个更优雅的方式,但现在这对我有用.我也在这里添加我的自定义消息处理程序.
[assembly: WebActivator.PreApplicationStartMethod(typeof(MyApp.AppStart.ApiBootstrapper), "Start")]
namespace MyApp.AppStart
{
public class ApiBootstrapper
{
public static void Start()
{
var kernel = new StandardKernel(new MyNinjectModule());
var resolver = new NinjectDependencyResolver(kernel);
GlobalConfiguration.Configuration.ServiceResolver.SetResolver(resolver.GetService, resolver.GetServices);
GlobalConfiguration.Configuration.MessageHandlers.Add(new ApiAuthHandler());
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在新的开发11预览中打开并转换现有的vs 2010 mvc 3项目,并且遇到了一个棘手的问题.解决方案文件将成功转换,但解决方案中的一个mvc 3 Web项目在解决方案资源管理器中显示为卸载后转换.当我尝试从解决方案资源管理器重新加载项目时,系统会提示我转换项目并在upgradelog.xml中收到以下错误
无法打开项目文件'myproject.csproj'.缺少项目子类型.子类型:此安装不支持'{E53F8FEA-EAE0-44A6-8774-FFD645390401}'.
从我可以追踪到的,这与MVC有关,但这并没有真正帮助我解决这个问题.任何建议或解决方法将不胜感激.