本文介绍了结合使用/中保(性爱巴士)到ninject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用与性爱巴士(并做类似:

Ninject works a bit differently.For the IRequestHandler<,> and INotificationHandler<> type bindings you should use ninject.extensions.conventions and do something like:

var kernel = new StandardKernel();

kernel.Bind(x => x.FromThisAssembly()
    .SelectAllClasses()
    .InheritedFromAny(
        new[]
        {
            typeof(ICommandHandler<>),
            typeof(IQueryHandler<,>)
        })
    .BindDefaultInterfaces());

kernel.Bind<IDependencyResolver>().ToMethod(x => DependencyResolver.Current);


ShortBus.DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));

您可能需要调整如下:


  • FromThisAssembly() - >这意味着只有类型,你写的这条线将被绑定的组装。您可以使用另一种机制,其中您可以指定哪些程序集寻找你的 ICommandHandler&LT;&GT; IQueryHandler&LT;,&GT; 类型。

  • BindDefaultInterfaces():见的的解释和替代。

  • FromThisAssembly() --> this means only types of the assembly where you write that line will be bound. You can use another mechanism where you specify in which assemblies to look for your ICommandHandler<> and IQueryHandler<,> types.
  • BindDefaultInterfaces(): See here for an explanation and alternatives.

另外请注意,我的例子code是根据。最新SHORTBUS的稳定的版本被引用StructureMap。

Also note that my example code is based upon ShortBus.Ninject 3.0.48-Beta. The most current ShortBus stable version is referencing StructureMap.

编辑:我看到你标记你的问题 asp.net StructureMap.Ninject ,它是不是使用的 NinjectDependencyResolver 你最好还是不要使用的(确保它是最新版本!)和 NinjectDependencyResolver Ninject.web.mvc 。

I see that you tagged your question asp.net. Instead of using StructureMap.Ninject and it's NinjectDependencyResolver you are probably better off using Ninject.Web.Common (make sure it's the latest version!) and NinjectDependencyResolver of Ninject.web.mvc.

这篇关于结合使用/中保(性爱巴士)到ninject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:23