Most controversial post, IoC, Ninject, just making it work

Where to begin?

In the course of teaching programming, everyone is faced with design patterns, architectural options, etc. For me, I understand conceptually DI, IoC and why they are needed / good. Modularity, high adhesion - I understand.

For example, I create a small test website using the MVP template, where the host does not have a specific view, but uses an interface that implements View. It also has a link to the service level (which is between the master and the BLL), again, nothing concrete, using the interface for this. All the good stuff.

(manual) IoC creates an instance of specific objects pushed up to the point that objects need to be entered somewhere, somewhere. In other words, the addiction still exists, it is only higher. Log into IoC containers. And enter the frustration.

I know what they are, I know what they are used for. I decided to use ninject. Cool. So, I'm starting to search. In my download, I have a bunch of files:

  • LICENSE.TXT
  • Ninject.dll
  • Ninject.pdb
  • Ninject.xml

another folder called extensions

  • CommonServiceLocator.NinjectAdapter.dll
  • CommonServiceLocator.NinjectAdapter.pdb

Ok ... a bunch of files. What to use? I dont know. Where do I place them? Do they need everything? Questions Questions ...

Perhaps read the instructions. Ninject wiki @github. Correctly. I'm starting to read - why use Ninject? Hand dependency injection, dependency injection with Ninject are good examples of swords and daggers, etc. But I don’t read anywhere how to actually do / use it. Where can I place it in Visual Studio? What do you call it? How?

He also presents me this code:

Bind<IWeapon>().To<Sword>(); 

It says that every time IWeapon is called, the implementation of the sword is given. Eh ... well, there was a dagger - maybe I don’t want to get a sword every time I have, for example. IWeapon as a parameter in my constructor, but how to do it? He does not speak! Am I stuck with a sword every time I use IWeapon? If not, then what is the code to change? And How?

It says that when you have a bunch of constructors, it will only accept one with more parameters. Good. What does he do with constructors that have a little less parameter than the constructor with the largest? Can I use ninject with these constructors? Or ... how does it work? Again - he doesn't say anywhere. Curses!

The wiki has a link to the most controversial mail on SO. It's about a guy named Joel, as they say something about the IoC, which enabled a fiery war / insensibility. But you know what? I dare say that I'm a little bit rude to this guy. What for? Maybe the concept of IoC is simple, but by God - bringing it to the end, knowing how to use it, what to do in case of certain situations, etc., really really upsets. A google search basically appears either nothing useful, or really a lot to read with collapsed material between them. I find that a guy may be right in a way - in that it’s really hard to understand the concepts and explain to someone who does not understand what you think is simple.

Why it doesn’t look like “Downloading files - pull this file out and place it somewhere conveniently, then go to Visual Studio, create a new map and access the DLL. To use it, follow these steps” and then explaining each step very well and a detailed explanation. No code snippets. This is frustrating.

So, you might wonder what my question is. Well, I want to use Ninject. What I need? where do i put it? How do I make it work? Should I be stuck with a sword everywhere in the world where I have IWeapon? What do I do at work when the sun shines outside?

+6
dependency-injection architecture ioc-container ninject
source share
2 answers

I have a very simple set of sample code for ninject, which I made for some of our developers when we introduced it to our project. It just covers basic bindings and such right now. Not as much as it works with MVC or more advanced topics such as context bindings. All this is done as nUnit tests, so I hope this is easy to follow. The fact that it does NOT show how to work with it correctly in your project. Hope you get a real MVC project example soon.

https://github.com/ryber/Ninject-Examples

Hope this helps.

+6
source share

For web projects, I recommend using MVC3. See https://github.com/ninject/ninject.web.mvc/wiki/MVC3 about working with Ninject.

+2
source share

All Articles