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.
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?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr.
C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.
C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.
You may create static wrapper class for kernel. That way you could do something like ServiceLocator.Resolve()
For registering services there are two ways: inline and module registration. Both of them should be loaded at bootstrapping. Module is better for organizing.
Maybe it would be easier to start with StructureMap because there is static class and it has auto mapping features.
Those screencasts should get you starting:
+1'd Marek's answer - definitely look through those resources.
Some points...
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.
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).
Surely there's a canonical 'Global Container' Singleton implementation out there for Ninject? EDIT: Just found one:- http://www.codethinked.com/creating-a-binding-factory-for-ninject
See also Ninject: How do I inject into a class library?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With