I am new with Ninject. Can someone help me to achieve what I want. I will give you my example. Please help me how you use NInject to get loose coupling.
Lets say I have an interface given below.
public interface IVehicle
{
PrintSpecification();
}
Now I have three classes implementing above interface. They could be as shown.
public class Car implements IVehicle
{
public void PrintSpecification()
{ Console.WriteLine("Specification for Car");}
}
public class Bus implements IVehicle
{
public void PrintSpecification()
{ Console.WriteLine("Specification for Bus");}
}
public class Truck implements IVehicle
{
public void PrintSpecification()
{ Console.WriteLine("Specification for Truck");}
}
Now in my main program I will have something like this. Here I have used new operator to create three concrete implementations of Car, Bus and Truck. I have to display the specification of all three vehicles. Now I wonder how do I write my Ninject codes so that there is no dependency of the concrete classes.
Public static void main()
{
IVehicle v1=new Car();
IVehicle v2=new Bus();
IVehicle v3=new Truck();
v1.PrintSpecification();
v2.PrintSpecification();
v3.PrintSpecification();
}