What is the intention of Ninject modules?

前端 未结 3 551
-上瘾入骨i
-上瘾入骨i 2020-12-04 23:05

I\'m a complete newbie to ninject

I\'ve been pulling apart someone else\'s code and found several instances of nInject modules - classes that derive from Ninject.Mod

3条回答
  •  情歌与酒
    2020-12-04 23:44

    Maybe I'm missing something obvious here, but what is the benefit of this over just creating a plain old class and calling its method, or perhaps a static class with a static method?

    Yes, you can just call a bunch of Bind().To() statements to setup the bindings, without a module.

    The difference is that if you put these statements in a module then:

    • IKernel.Load(IEnumerable) can dynamically discover such modules through reflection and load them.
    • the bindings are logically grouped together under a name; you can use this name to unload them again with IKernel.Unload(string)

提交回复
热议问题