C#,Ninject:您将内核和模块放在哪里? [英] C#, Ninject: Where do you put the kernel and your modules?

查看:60
本文介绍了C#,Ninject:您将内核和模块放在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个微型C#应用程序,该应用程序当前由一个核心程序集和一个winforms程序集组成.我意识到我可能真的不需要Ninject这样的小东西,但是我想尝试一下.

I'm creating a tiny C# application, which currently consists of a core assembly and a winforms assembly. I realize I probably don't really need Ninject in a small thing like this, but I would like to try it out.

无论如何,要与Ninject一起工作,我已经了解到您将编写一组模块,返回maps类,依此类推.之后,您将创建IKernel的实例并将模块加载到其中.

Anyways, to work with Ninject I have understood that you would write a set of modules, which maps class is returned and so on. After that you would create an instance of IKernel and load your modules into that.

但是,我应该将那些模块保存在哪里?那我应该把内核保存在哪里呢?东西去哪儿了?

But, where do I keep those modules? And where do I keep the kernel? Where do stuff go?

推荐答案

+1推荐了Marek的答案-肯定会浏览这些资源.

+1'd Marek's answer - definitely look through those resources.

一些要点...

即使在小型应用程序中,您绝对也可以尝试此操作.认真思考表面上的简单问题(例如您提出的问题)也很重要.对于DI,您确实必须真正地对其进行一些工作才能真正欣赏它-我曾经在哦,我只有一个小应用程序"(拒绝)阵营中呆了很长时间,直到我真正使用它为止

You're definitely right to try this, even in a small app. Its also important to think hard about superficially simple questions like the one you posed. For DI, you really do have to actually do some work with it to really appreciate it - I for one was in the "Oh, I've only got a small app" (denial) camp for a long time until I actually used it.

有一种流派,尽管一般来说应该绕开Service Locator并只进行注入(不依赖容器).

There's a school of though that one in general should be steering away from Service Locator and just having injection [without any dependencies on a container].

如果您不使用服务定位器,则没有人需要知道容器(内核)在哪里,这是最好的事情.

If you dont use Service Locators, nobody needs to know where the Container (Kernel) is, which is the best thing.

模块主要用于分隔成批的东西以在特定的整体容器(内核)中注册.

Modules are mainly for the purposes of compartmentalising batches of things to register in a particular overall Container (Kernel).

肯定有Ninject的规范"Global Container" Singleton实现吗?刚发现一个:- http://www.codethinked.com /为注射创建一个绑定工厂

Surely there's a canonical 'Global Container' Singleton implementation out there for Ninject? Just found one:- http://www.codethinked.com/creating-a-binding-factory-for-ninject

另请参见 Ninject:我该怎么办注入类库吗?

这篇关于C#,Ninject:您将内核和模块放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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