2013-02-08 45 views
0

我有一个类NinjectNinject - 基本使用

但我不知道Ninject这么高。

为什么总是要输入这个方法?

protected override IController GetControllerInstance(
    System.Web.Routing.RequestContext requestContext, 
    System.Type controllerType) 
{ 
    return controllerType == null 
    ? null 
    : (IController)ninjectKernel.Get(controllerType); 
} 
+1

你试过谷歌吗? – IronMan84 2013-02-08 20:32:42

+1

真正的铁人会说这样的话。 – 2013-02-08 22:45:16

回答

1

Ninject是一个IOC (Inversion of Control)包。

您总是打字的代码要求Ninject容器找到指定类型的控制器。

+1

值得一提的是,尽管Ninject是IOC,但使用'.Get'实际上与IOC相反 - 它使用Ninject作为服务定位器。 (尽管大概这是一个低级别的一次性的地方,在这种情况下会引发注入) – 2013-02-09 02:44:02