Ninject is a lightweight dependency injection framework for . NET applications. It helps you split your application into a collection of loosely-coupled, highly-cohesive pieces, and then glue them back together in a flexible manner.
Step 1: We are creating an instance of Class StandardKernel. Step 2: Then we will load the Kernel. Step 3: Get the instance of the specific service that we want to inject. Step 4: Then inject the dependency.
Ninject is and will always be free for both personal and commercial projects. It's also open source, so you can fork the code and make any changes you like.
What is Dependency Injection? A dependency is any object that another object requires. For example, it's common to define a repository that handles data access. Let's illustrate with an example.
Shameless plug: I have put together a very basic tutorial to get started with Ninject. Have a look at Ninject Mini-Tutorial Part1 and Ninject Mini-Tutorial Part2. That should help go get you started.
There you can find a reference to the source code on Github.
Ninject can be used with various types of Applications. It could be an ASP.NET WebForms application, ASP.NET MVC application or others.
For a detailed (with screenshots) step-by-step tutorial (with sample application to download) have a look at the following in addition to the Ninject "dojo" walkthrough that bryanray has mentioned.
http://peakbyte.wordpress.com/2009/09/28/how-to-use-ninject-ioc-with-asp-net-mvc/
Please note that this tutorial was written when ASP.NET MVC 2.0 was NOT released. Tiny modifications would be needed to get it working with ASP.NET MVC 2.0, like obtaining the appropriate Ninject.Framework.MVC.dll
Also take a look at these screencasts in DimeCast. Good starter.
Have you look at the ninject-contrib project at Google Code?
The Ninject "dojo" has a great walk through for getting started as well.
Update: The link that was initially provided was no longer valid. All the current documentation can be found on the Github wiki: http://wiki.github.com/ninject/ninject - Thanks, Martin.
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