Ninject – Dependency Injector


Ninject is the ninja of dependency injectors.Ninject is a lightning-fast, ultra-lightweight dependency injector 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. By using Ninject to support your software’s architecture, your code will become easier to write, reuse, test, and modify.

Example of Code:

interface IWeapon
{
    void Hit(string target);
}
class Samurai
{
    private IWeapon _weapon;
 
    [Inject]
    public Samurai(IWeapon weapon)
    {
        _weapon = weapon;
    }
 
    public void Attack(string target)
    {
        _weapon.Hit(target);
    }
}
class WarriorModule : StandardModule {
  public override Load() {
    Bind<IWeapon>().To<Sword>();
    Bind<Samurai>().ToSelf();
  }
}
class Program
{
    public static void Main()
    {
        IKernel kernel = new StandardKernel(new WarriorModule());
        Samurai warrior = kernel.Get<Samurai>();
        warrior.Attack("the evildoers");
    }
}

..

My Rank is: 8.8

Project Home Page:
http://ninject.org/
Codeplex Home Page:
http://ninject.codeplex.com/
Download:for .NET Framework 2.0, 3.0, 3.5 version 1.0
http://ninject.org/assets/dist/Ninject-1.0-release-net-2.0.zip

You dont need to reinventing the wheel 🙂

Advertisements

About bpostaci
Sr. Support Escalation Engineer in Microsoft.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: