If you already happen to be an expert and see any mistakes or have suggestions, I would appreciate feedback.
Download Source if you don't want to read and just want to see the code in action.
Let's take the following code:
public interface IMyObject
{
    string GetValue();
}
public class ImplMyObject : IMyObject
{
    public string GetValue()
    {
        return "ImplMyObject";
    }
}
public class MyObjectHandler
{
    public string GetValueFromMyObject(IMyObject myObj)
    {
        return myObj.GetValue();
    }
}static void Main(string[] args)
{
    ImplMyObject myObj = new ImplMyObject();
    MyObjectHandler handler = new MyObjectHandler();
    string myObjValue = handler.GetValueFromMyObject(myObj);
}Now, let's say we want to write a test case to test "MyObjectHandler." We could do the following:
public class MockMyObject : IMyObject
{
    public string GetValue()
    {
        return "MockMyObject";
    }
}
[TestMethod]
public void RegularSample()
{
    MockMyObject myObj = new MockMyObject();
    MyObjectHandler handler = new MyObjectHandler();
    Assert.AreEqual("MockMyObject", handler.GetValueFromMyObject(myObj));
}[TestMethod]
public void MoqObjectSample()
{
    var moqMyObj = new Mock<IMyObject>();
    moqMyObj.Setup(m => m.GetValue()).Returns("MoqObjectSample");
    MyObjectHandler handler = new MyObjectHandler();
    Assert.AreEqual("MoqObjectSample", handler.GetValueFromMyObject(moqMyObj.Object));
}Now, let's introduce Ninject into the picture. There may be times when you aren't able to pass interfaces around, or there are too many functions to pass it around if we have deep code and we can't possibly manage passing a DB connection object from our UI layer to our business layer and ultimately to the data access layer. We're still passing interfaces, but we just don't start at the top. So we can't really use Mock objects if we can't pass them in.
Let's look at the following example:
public class MyObjectHandler
{
    public string GetValueFromMyObject()
    {
        IMyObject myObj = new ImplMyObject();
        return myObj.GetValue();
    }
}internal class NinjectBootstrapper
{
    private static readonly Lazy<IKernel> _kernel = 
        new Lazy<IKernel>(() => new StandardKernel(new Bindings()));
    internal static IKernel Kernel
    {
        get { return _kernel.Value; }
    }
}
public class Bindings : NinjectModule
{
    public override void Load()
    {
        Bind<IMyObject>().To<ImplMyObject>();
    }
}public string GetValueFromMyObject()
{
    IMyObject myObj = NinjectBootstrapper.Kernel.Get<IMyObject>();
    return myObj.GetValue();
}[TestMethod]
public void NinjectRebindSample()
{
    NinjectBootstrapper.Kernel.Rebind<IMyObject>().To<MockMyObject>();
    MyObjectHandler handler = new MyObjectHandler();
    Assert.AreEqual("MockMyObject", handler.GetValueFromMyObject());
}[TestMethod]
public void MoqObjectSample()
{
    var moqMyObj = new Mock<IMyObject>();
    moqMyObj.Setup(m => m.GetValue()).Returns("MoqObjectSample");
    NinjectBootstrapper.Kernel.Rebind<IMyObject>().ToConstant(moqMyObj.Object);
    MyObjectHandler handler = new MyObjectHandler();
    Assert.AreEqual("MoqObjectSample", handler.GetValueFromMyObject());
} 










