2012-04-11 22 views
3

kernel.Bindに取得し、エラー(スキャナ => ... "スキャナ" は、2010年Ninject 3.0 MVC kernel.bindエラー自動登録

Cannot convert lambda expression to type 'System.Type[]' because it is not a delegate type

VSでその下の小さなエラー行を持っています追加されました。私は私が間違っているのかを把握することはできません。2.0の古いkernel.scanのように自動登録するに Tyringと非常に多くの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); 
      } 

答えて

12

あなたは

//using Ninject.Extensions.Conventions; 
+0

すでに試しました。私は、コメントとコメントを外しているすべての組み合わせを試していました。コメントを外すと、スキャナのエラーだけでなく、 "BindToDefaultInterface"が間違っていると表示されます。エラー: 'Ninject.Extensions.Conventions.Syntax.IJoinExcludeIncludeIncludeBindSyntax'に 'BindToDefaultInterface'の定義がなく、 'Ninject.Extensions.Conventions.Syntax.IJoinExcludeIncludeBindSyntax'タイプの最初の引数を受け入れる拡張メソッド 'BindToDefaultInterface'が見つかりませんでした(使用指示文またはアセンブリ参照がありませんか?) –

+0

これはBindDefaultInterfaceです –

+0

私のセットアップのどこかで大きな問題である必要があります。 .BindToDefaultInterface()は上記のVS2010エラーを取得します。 Ninject.Extensions.Conventionsのコメントが外されたときにビルドされません。 –

2

はちょうど私が私のエラーを取り除くために必要なアセンブリの一部を凝縮したかったコメントを解除する必要があります。相続人は私の完全なコードは、作品のthats> .BindDefaultInterface()

- おかげRemos

using System.Linq; //correct the .Any() error in the IsServiceType 
using Ninject; 
using Ninject.Web.Common; 
using Ninject.Extensions.Conventions; //Corrected the error with kernel.bind 

は.BindToDefaultInterfaceを()に変更しました。うまくいけば誰かを助けるだろう。

[assembly: WebActivator.PreApplicationStartMethod(typeof(LongRanch.App_Start.NinjectWebCommon), "Start")] 
[assembly: WebActivator.ApplicationShutdownMethodAttribute(typeof(LongRanch.App_Start.NinjectWebCommon), "Stop")] 

namespace LongRanch.App_Start 
{ 
    using System; 
    using System.Web; 
    using System.Linq; 
    using Microsoft.Web.Infrastructure.DynamicModuleHelper; 
    using Ninject; 
    using Ninject.Web.Common; 
    using Ninject.Extensions.Conventions; 
    using System.Reflection; 
    using System.IO; 
    using LR.Repository; 
    using LR.Repository.Interfaces; 
    using LR.Service.Interfaces; 
    using System.Web.Http; 
    using LR.Service; 

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

      GlobalConfiguration.Configuration 
       .ServiceResolver 
       .SetResolver(t => kernel.TryGet(t), 
          t => kernel.GetAll(t)); 

      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)) 
      kernel.Bind(scanner => scanner.From("LR.Repository", "LR.Service") 
       .Select(IsServiceType) 
       .BindDefaultInterface() 
       .Configure(binding => binding.InSingletonScope()) 
      ); 

     } 

     private static bool IsServiceType(Type type) 
     { 
      return type.IsClass && type.GetInterfaces().Any(intface => intface.Name == "I" + type.Name); 
     } 
    } 
} 
+0

この作品、ありがとう –

関連する問題