Ninject 3.0 MVC kernel.bind错误自动注册 [英] Ninject 3.0 MVC kernel.bind error Auto Registration

查看:302
本文介绍了Ninject 3.0 MVC kernel.bind错误自动注册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

获取和错误的kernel.Bind(扫描 => ...
扫描仪已在2010 VS它下面的小错误行。


  

无法转换拉姆达前pression键入'的System.Type []'
  因为它不是委托
  类型


Tyring为自动注册像老kernel.scan 2.0。
我想不出有什么我做错了。添加和删​​除这么多Ninject包。
完全丧失,越来越成为时间的巨大浪费。

 使用系统;
使用的System.Web;使用Microsoft.Web.Infrastructure.DynamicModuleHelper;使用Ninject;
使用Ninject.Web.Common;
使用Ninject.Extensions.Conventions //;
使用Ninject.Web.WebApi;
使用Ninject.Web.Mvc;
使用CommonServiceLocator.NinjectAdapter;
使用的System.Reflection;
使用System.IO;
使用LR.Repository;
使用LR.Repository.Interfaces;
使用LR.Service.Interfaces;
使用System.Web.Http;公共静态类NinjectWebCommon
{
    私人静态只读引导程序引导程序=新的引导程序();    ///<总结>
    ///启动应用
    ///< /总结>
    公共静态无效的start()
    {
        DynamicModuleUtility.RegisterModule(typeof运算(OnePerRequestHttpModule));
        DynamicModuleUtility.RegisterModule(typeof运算(NinjectHttpModule));
        bootstrapper.Initialize(CreateKernel);
    }    ///<总结>
    ///停止应用程序。
    ///< /总结>
    公共静态无效停止()
    {
        bootstrapper.ShutDown();
    }    ///<总结>
    ///创建将管理应用程序的内核。
    ///< /总结>
    ///<收益方式>创建的内核和LT; /回报>
    私有静态的iKernel CreateKernel()
    {
        VAR内核=新StandardKernel();
        kernel.Bind<&Func键LT;的iKernel>方式>()ToMethod(CTX =>()=>新建引导程序()内核。);
        kernel.Bind&所述; IHttpModule的方式>()到< HttpApplicationInitializationHttpModule>();        RegisterServices(内核);
        返回内核;
    }
    ///<总结>
    ///装入模块或在这里注册您服务!
    ///< /总结>
    ///< PARAM NAME =内核方式>内核< /参数>
            私有静态无效RegisterServices(内核的iKernel)
            {                kernel.Bind(扫描仪= GT; scanner.FromAssembliesInPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly()位置))。
                    。选择(IsServiceType)
                    .BindToDefaultInterface()
                    .Configure(绑定= GT; binding.InSingletonScope())
                    );            }            私人静态布尔IsServiceType(类型类型)
            {
                //临时回归真实;
                //。任何()也不会被识别。
                返回true; // type.IsClass&放大器;&安培; type.GetInterfaces()任何(intface => intface.Name ==我+ type.Name);
            }


解决方案

您必须取消注释

 使用Ninject.Extensions.Conventions //;

Getting and error on kernel.Bind(scanner => ... "scanner" has the little error line under it in VS 2010.

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

Tyring to Auto Register like the old kernel.scan in 2.0. I can not figure out what i am doing wrong. Added and removed so many Ninject packages. completely lost, getting to be a big waste of time.

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

解决方案

You have to uncomment

//using Ninject.Extensions.Conventions;

这篇关于Ninject 3.0 MVC kernel.bind错误自动注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆