获取和错误上kernel.Bind(扫描器 => ... “扫描仪” 已在VS它下面的小错误行2010年Ninject 3.0 MVC kernel.bind错误自动注册
Cannot convert lambda expression to type 'System.Type[]' because it is not a delegate type
Tyring为自动注册像老kernel.scan 2.0英寸 我想不出什么我做错了,添加和删除这么多Ninject包。 完全丧失,越来越成为时间的巨大浪费。
using System;
using System.Web;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using Ninject;
using Ninject.Web.Common;
//using Ninject.Extensions.Conventions;
using Ninject.Web.WebApi;
using Ninject.Web.Mvc;
using CommonServiceLocator.NinjectAdapter;
using System.Reflection;
using System.IO;
using LR.Repository;
using LR.Repository.Interfaces;
using LR.Service.Interfaces;
using System.Web.Http;
public static class NinjectWebCommon
{
private static readonly Bootstrapper bootstrapper = new Bootstrapper();
/// <summary>
/// Starts the application
/// </summary>
public static void Start()
{
DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
bootstrapper.Initialize(CreateKernel);
}
/// <summary>
/// Stops the application.
/// </summary>
public static void Stop()
{
bootstrapper.ShutDown();
}
/// <summary>
/// Creates the kernel that will manage your application.
/// </summary>
/// <returns>The created kernel.</returns>
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
kernel.Bind<Func<IKernel>>().ToMethod(ctx =>() => new Bootstrapper().Kernel);
kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
RegisterServices(kernel);
return kernel;
}
/// <summary>
/// Load your modules or register your services here!
/// </summary>
/// <param name="kernel">The kernel.</param>
private static void RegisterServices(IKernel kernel)
{
kernel.Bind(scanner => scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
.Select(IsServiceType)
.BindToDefaultInterface()
.Configure(binding => binding.InSingletonScope())
);
}
private static bool IsServiceType(Type type)
{
// temp return true;
// .Any() is not recognized either.
return true; // type.IsClass && type.GetInterfaces().Any(intface => intface.Name == "I" + type.Name);
}
已经试过了。我正在尝试评论和取消注释的所有组合。 Wheni取消注释,它不仅有扫描仪错误,它现在说“BindToDefaultInterface”是错误的。错误:'Ninject.Extensions.Conventions.Syntax.IJoinExcludeIncludeBindSyntax'不包含'BindToDefaultInterface'的定义,并且没有找到接受'Ninject.Extensions.Conventions.Syntax.IJoinExcludeIncludeBindSyntax'类型的第一个参数的扩展方法'BindToDefaultInterface'你是否缺少使用指令或程序集引用?) – 2012-04-11 12:00:25
它是BindDefaultInterface – 2012-04-11 13:06:14
在我的设置某处,必须是一个更大的问题。 .BindToDefaultInterface()获得上面的VS2010错误。当Ninject.Extensions.Conventions未被注释时,甚至不会构建。 – 2012-04-11 13:52:26